Python GET请求中的SSL错误 [英] SSL Error on Python GET Request

查看:201
本文介绍了Python GET请求中的SSL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对此网址执行简单的GET请求: link



以下是我已经用于其他网址和工程的基本Python代码。

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

在这个特定的URL中,我得到了一个SSL错误:

pre code> Traceback(最近一次调用最后一次)
Filefrances .py,第134行,在< module>
r = requests.get(url,verify = False)
获取$ b的文件/usr/local/lib/python2.7/dist-packages/requests/api.py,第55行$ b返回请求('get',url,** kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests/api.py,第44行,请求
return session.request(method = method,url = url,** kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests/sessions.py,第335行,请求
resp = self.send(prep,** send_kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests/sessions.py,第454行,in发送
history = [resp for resp in gen] if if allow_redirects else []
文件/usr/local/lib/python2.7/dist-packages/requests/sessions.py,第144行,在resolve_redirects
allow_redirects = False,
文件/usr/local/lib/python2.7/dist-packages/requests/sessions.py,第438行,发送
r = adapter。发送(请求,** kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests/adapters.py,第3行31,在发送
提高SSLError(E)
requests.exceptions.SSLError:[错误1] _ssl.c:504:错误:1408F119:SSL例程:SSL3_GET_RECORD:解密失败或不良记录MAC

有关使这个请求崩溃的特定网址发生了什么的任何想法?
我尝试添加自定义标题,但仍然没有运气。



预先感谢。

编辑:现在我试图用这种SSL方式作为答案。

  url ='https://www.bbvafrances.com .ar / francesGo2-门户/ institucional / busqueda.do M =&安培;页= 1' 
S = requests.Session()
s.mount(URL,SSLAdapter(ssl.PROTOCOL_SSLv3))
r = s.get(url)
print r.text

这是新的跟踪:(几乎与第一个相同)

pre $ code> Traceback(最近一次调用最后一次):
Filefrances。 py,第138行,在< module>
r = s.get(url)
文件/usr/local/lib/python2.7/dist-packages/requests/sessions.py,第463行,获取
return self .request('GET',url,** kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests/sessions.py,第451行,请求
resp = self.send(prep,** send_kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests/sessions.py,第557行,发送
r = adapter.send(request,** kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests/adapters.py,第420行,发送
raise SSLError(即,请求=请求)
requests.exceptions.SSLError:[错误1] _ssl.c:504:错误:1408F119:SSL例程:SSL3_GET_RECORD:解密失败或不良记录MAC

解决方案

问题是,服务器宣布支持TLS1.0,但如果你真的试图说话使用TLS1.0它会中断。您必须使用SSL3。



您可以使用<$ c $包含的 SSLAdapter c> requests_toolbelt 包:
http:/ /toolbelt.readthedocs.org/en/latest/user.html#ssladapter 然后使用 ssl.PROTOCOL_SSLv3 而不是文档中显示的那个。


I am trying to do a simple GET request to this url: link

Here's the basic python code which I already use for other urls and works.

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:

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? 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.

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. Instead you have to use SSL3.

You can do so by using the SSLAdapter included with the requests_toolbelt package: http://toolbelt.readthedocs.org/en/latest/user.html#ssladapter.

Then use ssl.PROTOCOL_SSLv3 instead of the one shown in the documentation.

这篇关于Python GET请求中的SSL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆