这不是 this question 的副本
我检查了this但不安全的方式对我来说并不好看。
我正在用 python 开发图像大小 getter ,它可以获取网页上图像的大小。在这样做之前,我需要获取网页状态代码。我试过这样做
import requests
hdrs = {'User-Agent': 'Mozilla / 5.0 (X11 Linux x86_64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 52.0.2743.116 Safari / 537.36'}
urlResponse = requests.get(
'http://aucoe.info/', verify=True, headers=hdrs)
print(urlResponse.status_code)
这给出了错误:
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
我尝试将 verify=True
更改为
verify='/etc/ssl/certs/ca-certificates.crt'
和
verify='/etc/ssl/certs'
但是还是报同样的错误。 我需要获取超过 5000 个 url 的状态代码。请帮助我。 提前致谢。
Python 版本:3.4
请求版本: requests==2.11.1
操作系统: Ubuntu 14.04
pyOpenSSL: 0.13
openssl 版本:OpenSSL 1.0.1f 2014 年 1 月 6 日
最佳答案
您需要下载 GoDaddy 根证书,可从 this site 获得然后将其作为参数传入verify
,如下所示:
>>> r = requests.get('https://aucoe.info', verify='/path/to/gd_bundle-g2-g1.crt')
>>> r.status_code
200
如果您将执行多个请求,您可能希望将 SSL 配置为 session 的一部分,如 documentation 中突出显示的那样.
关于python - 请求.exceptions.SSLError : [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl. c:600),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39737820/