requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:600) [英] requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

查看:77
本文介绍了requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:600)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是这个问题的重复

我检查了这个但不安全对我来说不好看.

我正在使用 python 中的图像大小获取器,它将获取网页上的图像大小.在此之前,我需要获取网页状态代码.我试过这样做

导入请求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)打印(urlResponse.status_code)

这给出了错误:

<块引用>

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:600)

我尝试将 verify=True 更改为

verify='/etc/ssl/certs/ca-certificates.crt'

verify='/etc/ssl/certs'

但它仍然给出相同的错误.我需要获取 5000 多个 url 的状态代码.请帮助我.提前致谢.

Python 版本: 3.4

请求版本:请求==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_code200

如果您要执行多个请求,您可能需要将 SSL 配置为会话的一部分,如 文档.

This is not a duplicate of this question

I checked this but going insecure way doesn't looks good to me.

I am working on image size fetcher in python, which would fetch size of image on a web page. Before doing that I need to get web page status-code. I tried doing this way

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)

This gives error:

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

I tried changing verify=True to

verify='/etc/ssl/certs/ca-certificates.crt'

and

verify='/etc/ssl/certs'

But it still gives the same error. I need to get status code for more than 5000 urls. Kindly help me. Thanks in advance.

Python Version : 3.4

Requests version : requests==2.11.1

O.S : Ubuntu 14.04

pyOpenSSL : 0.13

openssl version : OpenSSL 1.0.1f 6 Jan 2014

解决方案

You need to download the GoDaddy root certificates, available at this site and then pass it in as a parameter to verify, like this:

>>> r = requests.get('https://aucoe.info', verify='/path/to/gd_bundle-g2-g1.crt')
>>> r.status_code
200

If you'll be doing multiple requests, you may want to configure the SSL as part of the session, as highlighted in the documentation.

这篇关于requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:600)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆