首頁 > 後端開發 > Python教學 > 解決Python requests報錯方法總結

解決Python requests報錯方法總結

高洛峰
發布: 2017-03-20 09:19:04
原創
2316 人瀏覽過

這篇文章主要介紹了解決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

requests.exceptions.SSLError: [Errno 1] _ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate#verd failed#ver#n failed

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 報錯方法集錦,希望對大家有幫助,如果大家有任何疑問歡迎給我留言,小編會及時回覆大家的!

以上是解決Python requests報錯方法總結的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板