在mac os下使用Canopy中的PycURL下载数据High Sierra失败了

问题描述 投票:0回答:1

我尝试在python中编写两个函数,可用于从站点下载数据并将其保存为csv文件。

功能是:

def get_site_url( site_number='01589440', date_from="2008-01-01",date_to="2017-12-31" ): 
# input: site_number is a string
# the parameters in the url can have different formats. cb_00065 is the same as parameterCd=00060

#url = 'https://nwis.waterdata.usgs.gov/nwis/uv/cb_00065=on&format=rdb&site_no=%speriod=&begin_date=%s\
#&end_date=%s&siteStatus=all'%(site_number, date_from, date_to)

url = "https://nwis.waterdata.usgs.gov/nwis/uv/?parameterCd=00060,00065&format=rdb&site_no=%s&period=&begin_date=%s\
&end_date=%s&siteStatus=all"%(site_number, date_from, date_to)
return url

def download_data_from_url( url, savename='test.csv' ):
''' 
One can download data with a different method that supports resume. If data is two large then it takes
lot of time and the connection to the server might be interrupted.
'''

buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()

body = buffer.getvalue() # Body is a byte string.
with open( savename, 'w' ) as output:
    output.write( body.decode('utf-8')) # We have to know the encoding in order to print it to a text file

使用这两个函数作为下一个:

FirstExcUrl = get_site_url()
download_data_from_url(FirstExcUrl, '%s.csv'%'01589440')

产生了错误:

errorTraceback (most recent call last)
<ipython-input-5-f460d226bec2> in <module>()
      1 FirstExcUrl = get_site_url()
----> 2 download_data_from_url(FirstExcUrl, '%s.csv'%'01589440')

<ipython-input-3-e6e6e1be72e0> in download_data_from_url(url, savename)
     19     c.setopt(c.URL, url)
     20     c.setopt(c.WRITEDATA, buffer)
---> 21     c.perform()
     22     c.close()
     23 

error: (1, 'Protocol "https" not supported or disabled in libcurl')

它是一个jupyter笔记本的输出,是从一个好玩的Canopy编辑器窗口开始的。我从Canpy包管理器安装了curl和PycURL。安装的curl版本是:7.58.0-1,安装的PycURL版本是:7.19.5-5。

任何帮助,建议或解决方案都非常感谢。

curl jupyter-notebook canopy pycurl macos-high-sierra
1个回答
0
投票

抱歉,我们目前没有使用SSL支持构建libcurl。您可以使用另一个支持SSL的python包(例如请求)。

© www.soinside.com 2019 - 2024. All rights reserved.