python - 请求.exceptions.SSLError : [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl. c:600)

标签 python python-3.x ssl ssl-certificate python-requests

这不是 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/

相关文章:

python - 在python imaplib中解析带括号的列表

python - Flask 登录 - @login_manager.token_loader 未被调用

比较列表中所有相邻元素的 Pythonic 方式

python - 使用 asyncio 与其他对等方连接时如何处理 ConnectionRefusedError

ssl - Mule ESB 3.3 - 接收 IMAPS 邮件 (Gmail)

node.js - 不带 ssl 的 npm 安装

python - 单击按钮时 kivy 加载相机(zbarscan)

Python3.6 不显示 Sublime-Text 3 中的输出

ssl - 使用自签名证书是否可以防止中间人攻击?

python - 查找名称中带有特殊字符的目录中的文件