Загрузка данных с использованием PycURL в Canopy под mac os High Sierra не удалась

Я попытался написать две функции на 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. Я установил и curl, и PycURL из менеджера пакетов Canpy. Установленная версия curl: 7.58.0-1, а установленная версия PycURL: 7.19.5-5.

Любая помощь, предложение или решение высоко ценится.


person Gergely Mathe    schedule 20.02.2019    source источник


Ответы (1)


К сожалению, в настоящее время мы не собираем libcurl с поддержкой SSL. Вы можете использовать другой пакет Python (например, запросы), который поддерживает SSL.

person Jonathan March    schedule 20.02.2019
comment
Большое спасибо за ответ! - person Gergely Mathe; 21.02.2019