如題訪問部分私有SSL證書網站時報以下錯誤python
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
測試環境linux
kali linux 1.1.0 Python 2.7.8 python-openssl 0.13-2+deb7u1 requests 2.3.0
測試代碼shell
#/usr/bin/python #coding=utf-8 import requests def getHtml(): #自定義的證書須要指定自動忽略對SSL證書的驗證 req = requests.get('https://hg.mornie.org',verify=False) print req.text if __name__ == '__main__': getHtml()
如上測試會報錯誤以下api
Traceback (most recent call last): File "/root/Desktop/erp.py", line 32, in <module> getHtml() File "/root/Desktop/erp.py", line 25, in getHtml req = requests.get('https://hg.mornie.org',verify=True) File "/usr/local/lib/python2.7/dist-packages/requests-2.3.0-py2.7.egg/requests/api.py", line 55, in get return request('get', url, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.3.0-py2.7.egg/requests/api.py", line 44, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.3.0-py2.7.egg/requests/sessions.py", line 456, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.3.0-py2.7.egg/requests/sessions.py", line 559, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.3.0-py2.7.egg/requests/adapters.py", line 382, in send raise SSLError(e, request=request) requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
在國外搜索了半天資料後,發現是最近官方出現的一個bug,現已修復,可更新session
在更新python-openssl包到0.14-1~kali1後成功解決問題(或者更新到最新版本)python2.7