如何让 Python 请求信任自签名 SSL 证书? [英] How to get Python requests to trust a self signed SSL certificate?
本文介绍了如何让 Python 请求信任自签名 SSL 证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import requests
data = {'foo':'bar'}
url = 'https://foo.com/bar'
r = requests.post(url, data=data)
如果 URL 使用自签名证书,则失败并显示
If the URL uses a self signed certificate, this fails with
requests.exceptions.SSLError: [Errno 1] _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
我知道我可以将 False
传递给 verify
参数,就像这样:
I know that I can pass False
to the verify
parameter, like this:
r = requests.post(url, data=data, verify=False)
但是,我想做的是将请求指向磁盘上公钥的副本,并告诉它信任该证书.
However, what I would like to do is point requests to a copy of the public key on disk and tell it to trust that certificate.
推荐答案
尝试:
r = requests.post(url, data=data, verify='/path/to/public_key.pem')
这篇关于如何让 Python 请求信任自签名 SSL 证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文