问题描述
我无法在没有收到错误[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败
的情况下请求流行的 SSL 站点.
I cannot request a popular SSL site without geting the error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
.
请求文档指出
默认情况下,Requests 捆绑了一组它信任的根 CA,来源来自 Mozilla 信托商店.但是,这些仅更新一次每个请求版本.这意味着如果您固定请求版本您的证书可能会变得非常过时.
因为这是一个受欢迎的网站,所以当我使用 verify=True
时它应该在商店中,但是它总是失败.我也尝试过使用其他 SSL 地址,但它也因此错误而失败.
As this is a popular site it should be in the store when I use verify=True
, however it keeps failing. I have also tried with other SSL addresses and it also fails with this error.
import requests
headers = {
'User-agent': 'Mozilla/5.0'
}
proxies = {
'http' : 'http://1.2.3.4:80',
'https' : 'http://1.2.3.4:443'
}
r = requests.get('https://www.example.com', proxies=proxies, verify=True)
请注意,https://www.example.com 是一个受欢迎的英国新闻网站,因此它应该是在 CA 商店中.
Note that https://www.example.com is a popular UK news website, so it should be in the CA store.
Python 版本:Python 2.7.11
Python Version: Python 2.7.11
请求版本:请求 (2.10.0)
Requests Version: requests (2.10.0)
操作系统:Windows 8
我做错了什么吗?
推荐答案
r = requests.get('https://www.example.com', proxies=proxies, verify=False)
更改此行,它将起作用.
Change this line and it will work.
这篇关于requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!