简体   繁体   English

Python GET请求上的SSL错误

[英]SSL Error on Python GET Request

I am trying to do a simple GET request to this url: link 我正在尝试对此网址执行简单的GET请求: 链接

Here's the basic python code which I already use for other urls and works. 这是我已经用于其他网址和工作方式的基本python代码。

url = 'http://www.bbvafrances.com.ar/francesGo2-Portal/institucional/busqueda.do?m=&page=1'
r = requests.get(url)
print r.text

The thing is that with this particular url I get an SSL error: 问题是,使用此特定网址,我会收到一个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

Any ideas on what is going on with this particular url that makes the request crash? 关于使请求崩溃的特定URL发生了什么的任何想法? I tried adding custom headers but still no luck. 我尝试添加自定义标头,但仍然没有运气。

Thanks in advance. 提前致谢。

EDIT: Now I'm trying with this SSL way suggested as an answer. 编辑:现在我正在尝试使用这种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

This is the new trace: (almost identical to the first one) 这是新的跟踪:(几乎与第一个相同)

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

The problem is, that the server announces support for TLS1.0 but if you actually try to talk to it using TLS1.0 it will break. 问题是,服务器宣布支持TLS1.0,但是如果您实际上尝试使用TLS1.0与之交谈,它将中断。 Instead you have to use SSL3. 相反,您必须使用SSL3。

You can do so by using the SSLAdapter included with the requests_toolbelt package: http://toolbelt.readthedocs.org/en/latest/user.html#ssladapter . 您可以通过使用requests_toolbelt软件包随附的SSLAdapter来做到这SSLAdapterhttp : SSLAdapter

Then use ssl.PROTOCOL_SSLv3 instead of the one shown in the documentation. 然后,使用ssl.PROTOCOL_SSLv3代替文档中显示的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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