使用请求验证 SSL 证书 [英] Verify SSL certificate with Requests
问题描述
我正在尝试验证 SSL,但它不起作用.
I'm trying to verify SSL but it doesn't work.
- 我在浏览器上访问了我想访问的机密网站.
- 在 Chrome 上,我点击了储物柜 >证书 >详情>在文件中复制 >基数 64 >证书
我的代码是:
test = requests.get('https://confidential.xx/', verify='certif.cer')
错误是:
文件C:\Users\xxxxx\Downloads\WinPython\WPy64-3850\python-3.8.5.amd64\lib\site-packages\requests\adapters.py",第 514 行,发送引发 SSLError(e, request=request)
File "C:\Users\xxxxx\Downloads\WinPython\WPy64-3850\python-3.8.5.amd64\lib\site-packages\requests\adapters.py", line 514, in send raise SSLError(e, request=request)
SSLError: HTTPSConnectionPool(host='xxxxx',端口 = 443):超过最大重试次数,网址为:/(由SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED]证书验证失败:证书中的自签名证书链 (_ssl.c:1123)')))
SSLError: HTTPSConnectionPool(host='xxxxx', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)')))
我不想使用有效但不安全的 verify=False.
I don't wanna use verify=False which works but not securised.
我尝试过使用和不使用代理,同样的错误...
I have tried with and without the proxies, same error...
我需要让它工作,请问如何让这段代码工作?
I need to make this working, how make this code working please ?
推荐答案
为了使 requests
不抱怨有效证书,提供给 verify=
的证书必须包含任何中间证书.下载全链可以使用火狐(截图):
To make requests
not complain about valid certificate, the certificate supplied to verify=
must contain any intermediate certificates. To download full chain, you can use Firefox (screenshots):
这篇关于使用请求验证 SSL 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!