执行以下脚本时,我在 Ubuntu 14.04 中使用 python 请求库时遇到问题:
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 中尝试相同的代码可以正常工作
我客人这个错误与openssl(1.0.1f)的版本有关,并请求python库
我尝试按照使用带有 TLS 的请求中的建议安装 pyOpenSSL、ndg-httpsclient 和 pyasn1不提供 SNI 支持但不起作用,还在运行脚本之前应用猴子补丁但也失败了
注意:当我使用 pyOpenSSL 时,我得到的新错误是:
request.exceptions.SSLError: [Errno bad handshake](104, 'ECONNRESET')
感谢您的任何建议