Python请求和OpenSSL-超过HTTPSConnectionPool Max重试 [英] Python requests and OpenSSL - HTTPSConnectionPool Max retries exceeded
问题描述
执行以下脚本时,我在Ubuntu 14.04中使用python请求库时遇到问题:
I have a problem using python requests library in Ubuntu 14.04 when execute the following script:
import requests
import json
payload = {'code':'TG-000000000000000000000000', 'client_secret':'X0000000000000000000000000000000', 'grant_type':'authorization_code', 'client_id':'1111111111111111', 'redirect_uri':'http://127.0.0.1:8000/mercadolibre/process_ml_response/'}
headers = {'content-type': 'application/x-www-form-urlencoded'}
requests.post("https://api.mercadolibre.com:443/oauth/token", data=payload, headers=headers)
我得到以下回溯
File "<stdin>", line 1, in <module>
File "/home/theuser/.virtualenvs/tumoto/local/lib/python2.7/site-packages/requests/api.py", line 88, in post
return request('post', url, data=data, **kwargs)
File "/home/theuser/.virtualenvs/tumoto/local/lib/python2.7/site-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/home/theuser/.virtualenvs/tumoto/local/lib/python2.7/site-packages/requests/sessions.py", line 456, in request
resp = self.send(prep, **send_kwargs)
File "/home/theuser/.virtualenvs/tumoto/local/lib/python2.7/site-packages/requests/sessions.py", line 559, in send
r = adapter.send(request, **kwargs)
File "/home/theuser/.virtualenvs/tumoto/local/lib/python2.7/site-packages/requests/adapters.py", line 375, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.mercadolibre.com', port=443): Max retries exceeded with url: /oauth/token (Caused by <class 'socket.error'>: [Errno 104] Connection reset by peer)
如果我在Ubuntu 13.10中尝试相同的代码,效果很好
If I try the same code in Ubuntu 13.10 works fine
我为这个错误与openssl(1.0.1f)的版本有关,并请求python库
I guest this error is related to the version of openssl (1.0.1f) and requests python library
我尝试按照使用带有TLS的请求不能提供SNI支持,但不起作用,还可以在运行脚本之前应用猴子补丁,但也会失败
I try installing pyOpenSSL, ndg-httpsclient and pyasn1 as is suggested in using requests with TLS doesn't give SNI support but doesn't work, also apply the monkey patch before run the script but also fails
注意:当我使用pyOpenSSL时,我得到的新错误是:
Note: when I use pyOpenSSL then the new error that I get is:
request.exceptions.SSLError: [Errno bad handshake](104, 'ECONNRESET')
感谢您的任何建议
推荐答案
我发现了一批请求,这些请求与Ubuntu 14.04的OpenSSL版本可以很好地配合使用,
I found a fork of requests that works fine with OpenSSL version of Ubuntu 14.04, https://github.com/joequery/requests-sslv3 only install this fork via pip and requests works well again
这篇关于Python请求和OpenSSL-超过HTTPSConnectionPool Max重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!