简体   繁体   中英

Error downloading a file using python package requests with https

I'm a begginer in Python and have been struggling with downloading a file using the package requests. My code works for an url with http, but not for https. The code is the following:

import requests
url = 'https://firms.modaps.eosdis.nasa.gov/active_fire/shapes/zips/Central_America_24h.zip'

print "downloading with requests"
r = requests.get(url)
with open("Central_America_24h.zip", "wb") as code:
    code.write(r.content) 

I get the following errors:

Warning (from warnings module):
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 90
    InsecurePlatformWarning
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

Traceback (most recent call last):
  File "C:\Users\lmixco\Downloads\descarga.py", line 8, in <module>
    r = requests.get(url)
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\api.py", line 68, in get
    return request('get', url, **kwargs)
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 594, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 196, in resolve_redirects
    **adapter_kwargs
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\adapters.py", line 431, in send
    raise SSLError(e, request=request)
SSLError: [Errno 8] _ssl.c:503: EOF occurred in violation of protocol

I have been looking for a solution, but have not found anything. Any help will be appreciated. Thanks in advance.

you need to install a package , use this

pip install requests[security]

for debain / ubuntu , install this before installing above package

apt-get install python-dev libffi-dev libssl-dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM