這篇文章主要介紹了解決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 configrox 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 <module>
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_response
File "build/bdist.linux-x86_64/modpy." , line 611, in send
cailed##ver# #可以停用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 verllify failed')],) python2.7.55dinstad -y certifi && pip install certifi==2015.04.28
討論參見: https://github.com/rackspace/pyrax/issues/601
以上是解決Python requests報錯方法總結的詳細內容。更多資訊請關注PHP中文網其他相關文章!