如题访问部分私有SSL证书网站时报如下错误
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
测试环境
kali linux 1.1.0 Python 2.7.8 python-openssl 0.13-2+deb7u1 requests 2.3.0
测试代码
#/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()
如上测试会报错误如下
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,现已修复,可更新
在更新python-openssl包到0.14-1~kali1后成功解决问题(或者更新到最新版本)