Python 发送带有证书、私钥和密码的请求的代码

Python code for sending requests with certificate, private encrypted key and password

我正在尝试从 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)

会抛出错误

Caused by SSLError('Client private key is encrypted, password is required'

求推荐。

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

The private key to your local certificate must be unencrypted. Currently, Requests does not support using encrypted keys.

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