我试图从Internet和Python2.7.15cr1下载PDF文件并请求2.19.1,但我遇到此错误:
> Traceback (most recent call last):
> File "download.py", line 5, in <module>
> r = requests.get(url,verify=False)
> File "/home/user/.local/lib/python2.7/site-packages/requests/api.py",
> line 72, in get
> return request('get', url, params=params, **kwargs)
> File "/home/user/.local/lib/python2.7/site-packages/requests/api.py",
> line 58, in request
> return session.request(method=method, url=url, **kwargs)
> File "/home/user/.local/lib/python2.7/site-packages/requests/sessions.py",
> line 512, in request
> resp = self.send(prep, **send_kwargs)
> File "/home/user/.local/lib/python2.7/site-packages/requests/sessions.py",
> line 622, in send
> r = adapter.send(request, **kwargs)
> File "/home/user/.local/lib/python2.7/site-packages/requests/adapters.py",
> line 511, in send
> raise SSLError(e, request=request)
> requests.exceptions.SSLError: HTTPSConnectionPool(host='host', port=443): Max
> retries exceeded with url: /en/files/pdftodownload.pdf
> (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines',
> 'ssl3_read_bytes', 'sslv3 alert handshake failure')],)",),))
我用来尝试下载PDF文件的代码是:
import requests
url = 'https://www.gasnaturalfenosa.com/en/files/GasNaturalSDG_ing_2016-2.pdf'
r = requests.get(url, stream=True)
with open('metadata.pdf', 'wb') as fd:
for chunk in r.iter_content(chunk_size=2048):
fd.write(chunk)
如果我尝试使用curl下载它,则会遇到相同的错误。 我一直在尝试纠正此错误已有好几天,因此,如果有人可以给我提示为什么会发生这种情况,我将不胜感激!
提前谢谢!
答案 0 :(得分:1)
该服务器已损坏。根据{{3}},它仅支持TLS 1.0,并且仅支持使用DES或3DES的不安全或弱密码。默认情况下,在请求中禁用这些密码。
如果仍然要连接到服务器,则需要明确允许弱3DES密码。如SSLLabs report中所述,它的工作方式如下:
import requests
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'DES-CBC3-SHA'
resp=requests.get('https://www.gasnaturalfenosa.com/en/files/GasNaturalSDG_ing_2016-2.pdf')