且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在python中使用带有请求的自签名证书

更新时间:2022-04-22 22:21:07

这个问题很老但是如果有人想知道这里。

This question is old but In case someone wonders off here.

您将私钥和公钥放在test.pem中。这是错的。验证参数需要的是它可以信任的证书。

You are putting the private key and public key in you test.pem. This is wrong. What verify param requires is certs which it can trust.

res = requests.get('https://my-pre-prod-site.com/login', verify = os.path.join(os.getcwd(),'test.pem')

测试。 pem应该包含所有可信证书的列表。但是你在test.pem中提供的是你的公钥和私钥。你〜/ Desktop / CertPath / certificate.pem文件本身应该进入它。

The test.pem is supposed to contain the list of all the Trusted Certificates. But what you're providing in your test.pem is your public and private key. You're ~/Desktop/CertPath/certificate.pem file itself should go into it.

试试这个:

res = requests.get('https://my-pre-prod-site.com/login', verify = '~/Desktop/CertPath/certificate.pem')