我正在尝试对此网址执行简单的GET请求:link
这是我已经用于其他网址和工作的基本python代码。
url = 'http://www.bbvafrances.com.ar/francesGo2-Portal/institucional/busqueda.do?m=&page=1'
r = requests.get(url)
print r.text
问题在于,使用此特定网址时,我收到了SSL错误:
Traceback (most recent call last):
File "frances.py", line 134, in <module>
r = requests.get(url,verify=False)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 335, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 454, in send
history = [resp for resp in gen] if allow_redirects else []
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 144, in resolve_redirects
allow_redirects=False,
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 438, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 331, in send
raise SSLError(e)
requests.exceptions.SSLError: [Errno 1] _ssl.c:504: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
关于此特定网址发生什么事情的任何想法都会导致请求崩溃? 我尝试添加自定义标题但仍然没有运气。
提前致谢。
编辑:现在我正在尝试使用这种SSL方式作为答案。
url = 'https://www.bbvafrances.com.ar/francesGo2-Portal/institucional/busqueda.do?m=&page=1'
s = requests.Session()
s.mount(url, SSLAdapter(ssl.PROTOCOL_SSLv3))
r = s.get(url)
print r.text
这是新的痕迹:(几乎与第一个相同)
Traceback (most recent call last):
File "frances.py", line 138, in <module>
r = s.get(url)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 463, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 451, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 557, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 420, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 1] _ssl.c:504: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
答案 0 :(得分:0)
问题是,服务器宣布支持TLS1.0,但如果你真的尝试使用TLS1.0与它交谈,它将会中断。相反,你必须使用SSL3。
您可以使用SSLAdapter
包中附带的requests_toolbelt
来执行此操作:
http://toolbelt.readthedocs.org/en/latest/user.html#ssladapter
然后使用ssl.PROTOCOL_SSLv3
而不是文档中显示的那个。