python requests请求失败重试,Python请求和OpenSSL-超过HTTPSConnectionPool Max重试

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)

I get the following traceback

File "", line 1, in

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 : [Errno 104] Connection reset by peer)

If I try the same code in Ubuntu 13.10 works fine

I guest this error is related to the version of openssl (1.0.1f) and requests python library

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

Note: when I use pyOpenSSL then the new error that I get is:

request.exceptions.SSLError: [Errno bad handshake](104, 'ECONNRESET')

Thanks for any suggestion

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值