python - 用于发送带有证书、私有加密密钥和密码的请求的 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:
本地证书的私钥必须未加密。目前,Requests 不支持使用加密密钥。
有关如何删除密钥加密的说明,请参阅https://security.stackexchange.com/questions/59136/can-i-add-a-password-to-an-existing-private-key 。
推荐阅读
- elasticsearch - 弹性搜索我所有的索引都显示为红色。可能是什么原因以及如何解决这个问题?
- python - 如何使用 Python 将 JSON 数据转换为 Avro 格式
- r - R条件两个变量的新变量
- for-loop - 使用 Windows 命令行 FOR 循环从文件中读取带有空格的路径
- microservices - 任何单体应用程序开发的设计实践可以轻松转换为微服务?
- javascript - if 语句中的 switch 语句未执行
- java - 我想计算我编写此代码的最近 20 个闰年,是否可以进一步优化此代码
- git - GIT 推送错误缺少凭据或凭据无效
- arrays - 如何在 Rust 的结构中实现动态二维数组?
- django - 不能将 UserAdmin 文件集与自定义用户模型一起使用