解決Python requests 報錯方法集錦
python版本和ssl版本都會導(dǎo)致 requests在請求https網(wǎng)站時候會出一些錯誤,最好使用新版本。
1 Python2.6x use requests
一臺老Centos機器上跑著古老的應(yīng)用,加了一個新模塊之后報錯 報錯 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 <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_64/egg/requests/models.py", line 611, in send
requests.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 報錯方法集錦,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!
- python中requests模塊的使用方法
- python中requests庫session對象的妙用詳解
- python采用requests庫模擬登錄和抓取數(shù)據(jù)的簡單示例
- Python使用requests發(fā)送POST請求實例代碼
- python中requests使用代理proxies方法介紹
- python?如何使用requests下載文件
- Python爬蟲庫requests獲取響應(yīng)內(nèi)容、響應(yīng)狀態(tài)碼、響應(yīng)頭
- Python3使用requests包抓取并保存網(wǎng)頁源碼的方法
- 詳解Python requests 超時和重試的方法
- Python requests timeout的設(shè)置
- Python中Requests庫的實現(xiàn)示例
相關(guān)文章
Python入門_淺談for循環(huán)、while循環(huán)
下面小編就為大家?guī)硪黄狿ython入門_淺談for循環(huán)、while循環(huán)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05python中?OpenCV和Pillow處理圖像操作及時間對比
這篇文章主要介紹了python中OpenCV和Pillow處理圖像操作及時間對比,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09Python中使用urllib2防止302跳轉(zhuǎn)的代碼例子
這篇文章主要介紹了Python中使用urllib2防止302跳轉(zhuǎn)的代碼例子,即避免302跳轉(zhuǎn)的實現(xiàn),需要的朋友可以參考下2014-07-07Python將GIF動圖轉(zhuǎn)換為Base64編碼字符串的步驟詳解
在Web開發(fā)中,有時需要將圖像文件(如GIF動圖)轉(zhuǎn)換為Base64編碼的字符串,以便在HTML或CSS中直接嵌入圖像數(shù)據(jù),本文給大家就介紹了一個簡單的教程,教你如何使用Python將GIF動圖轉(zhuǎn)換為Base64編碼的字符串,需要的朋友可以參考下2025-02-02