用于发送带有证书,私有加密密钥和密码的请求的Python代码

问题描述

我正试图从安装了证书的https调用获取响应。这是我的代码

import requests
import urllib3

urllib3.disable_warnings()

cert_file_path = "/path/output-crt-file-name.crt"
key_file_path = "/path/output-key-file-name.key"
passwd = 'secretpass'
print(passwd)
url = "https://url/to/fetch/response"
params = {"AppID": "xxxx","Safe": "xxxx","Folder": "Root","Object": "xxxx"}
cert = (cert_file_path,key_file_path,passwd)
r = requests.get(url,params=params,cert=cert,verify=True )
print(r.text)

会引发错误

由SSLError引起((“客户端私钥已加密,需要密码”

请提出建议。

解决方法

恐怕请求当前不支持使用加密的私钥,请参阅https://2.python-requests.org/en/master/user/advanced/#client-side-certificates

本地证书的私钥必须未加密。 当前,“请求”不支持使用加密密钥。

有关如何删除密钥加密的说明,请参见https://security.stackexchange.com/questions/59136/can-i-add-a-password-to-an-existing-private-key