解決Python requests 報(bào)錯(cuò)方法集錦
python版本和ssl版本都會(huì)導(dǎo)致 requests在請(qǐng)求https網(wǎng)站時(shí)候會(huì)出一些錯(cuò)誤,最好使用新版本。
1 Python2.6x use requests
一臺(tái)老Centos機(jī)器上跑著古老的應(yīng)用,加了一個(gè)新模塊之后報(bào)錯(cuò) 報(bào)錯(cuò) 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
錯(cuò)誤如下 版本 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)
問(wèn)題地址 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
討論參見(jiàn): https://github.com/rackspace/pyrax/issues/601
以上所述是小編給大家介紹的Python requests 報(bào)錯(cuò)方法集錦,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
- python中requests模塊的使用方法
- python中requests庫(kù)session對(duì)象的妙用詳解
- python采用requests庫(kù)模擬登錄和抓取數(shù)據(jù)的簡(jiǎn)單示例
- Python使用requests發(fā)送POST請(qǐng)求實(shí)例代碼
- python中requests使用代理proxies方法介紹
- python?如何使用requests下載文件
- Python爬蟲(chóng)庫(kù)requests獲取響應(yīng)內(nèi)容、響應(yīng)狀態(tài)碼、響應(yīng)頭
- Python3使用requests包抓取并保存網(wǎng)頁(yè)源碼的方法
- 詳解Python requests 超時(shí)和重試的方法
- Python requests timeout的設(shè)置
- Python中Requests庫(kù)的實(shí)現(xiàn)示例
相關(guān)文章
Python入門(mén)_淺談for循環(huán)、while循環(huán)
下面小編就為大家?guī)?lái)一篇Python入門(mén)_淺談for循環(huán)、while循環(huán)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05python中?OpenCV和Pillow處理圖像操作及時(shí)間對(duì)比
這篇文章主要介紹了python中OpenCV和Pillow處理圖像操作及時(shí)間對(duì)比,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09django中操作mysql數(shù)據(jù)庫(kù)的方法
對(duì)象關(guān)系映射模式是一種為了解決面向?qū)ο笈c關(guān)系數(shù)據(jù)庫(kù)存在的互不匹配的現(xiàn)象的技術(shù),這篇文章主要介紹了django中操作mysql數(shù)據(jù)庫(kù)的方法,需要的朋友可以參考下2022-09-09探究Python多進(jìn)程編程下線程之間變量的共享問(wèn)題
這篇文章主要介紹了探究Python多進(jìn)程編程下線程之間變量的共享問(wèn)題,多進(jìn)程編程是Python學(xué)習(xí)進(jìn)階中的重要知識(shí),需要的朋友可以參考下2015-05-05Python中使用urllib2防止302跳轉(zhuǎn)的代碼例子
這篇文章主要介紹了Python中使用urllib2防止302跳轉(zhuǎn)的代碼例子,即避免302跳轉(zhuǎn)的實(shí)現(xiàn),需要的朋友可以參考下2014-07-07Python將GIF動(dòng)圖轉(zhuǎn)換為Base64編碼字符串的步驟詳解
在Web開(kāi)發(fā)中,有時(shí)需要將圖像文件(如GIF動(dòng)圖)轉(zhuǎn)換為Base64編碼的字符串,以便在HTML或CSS中直接嵌入圖像數(shù)據(jù),本文給大家就介紹了一個(gè)簡(jiǎn)單的教程,教你如何使用Python將GIF動(dòng)圖轉(zhuǎn)換為Base64編碼的字符串,需要的朋友可以參考下2025-02-02