解决pythonrequests报错方法总结

这篇文章主要介绍了解决python requests 报错方法集锦的相关资料,需要的朋友可以参考下

python版本和ssl版本都会导致 requests在请求https网站时候会出一些错误,最好使用新版本。

1 python2.6x use requests

一台老centos机器上跑着古老的应用,加了一个新模块之后报错 报错 insecureplatformwarning: a true sslcontext object is not available.

/usr/lib/python2.6/site-packages/requests/packages/urllib3/util/ssl_.py:132: insecureplatformwarning: a true sslcontext object is not available. this prevents urllib3 from configuring ssl appropriately and may cause certain ssl connections to fail. you can upgrade to a newer version of python to solve this. for more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings insecureplatformwarning

解决办法

使用老版本的 requests

$pip install requests==2.5.3

或者这样安装

$ pip install requests[security]

2 ssl3_get_server_certificate:certificate verify failed

错误如下 版本 python2.7.5

traceback (most recent call last): file “./test.py”, line 24, in response = requests.get(url1, headers=headers) file “build/bdist.linux-x86_64/egg/requests/api.py”, line 52, in get file “build/bdist.linux-x86_64/egg/requests/api.py”, line 40, in request file “build/bdist.linux-x86_64/egg/requests/sessions.py”, line 209, in request file “build/bdist.linux-x86_64/egg/requests/models.py”, line 624, in send file “build/bdist.linux-x86_64/egg/requests/models.py”, line 300, in _build_response file “build/bdist.linux-x86_64/egg/requests/models.py”, line 611, in sendrequests.exceptions.sslerror: [errno 1] _ssl.c:503: error:14090086:ssl routines:ssl3_get_server_certificate:certificate verify failed

解决方法

可以禁用 verify

>>> requests.get(‘https://google.com’, verify=true)问题地址 python-requests-throwing-up-sslerror

3 sslerror: bad handshake

sslerror: bad handshake: error([(‘ssl routines’, ‘ssl3_get_server_certificate’, ‘certificate verify failed’)],) python2.7.5 pip uninstall -y certifi && pip install certifi==2015.04.28

讨论参见: https://github.com/rackspace/pyrax/issues/601

以上所述是小编给大家介绍的python requests 报错方法集锦,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

以上就是解决python requests报错方法总结的详细内容,更多请关注 第一php社区 其它相关文章!

Posted in 未分类

发表评论