【发布时间】:2021-03-24 01:09:19
【问题描述】:
我的问题
我在使用python requests 时尝试使用加密的客户端私钥。由于它不支持加密密钥,我必须先将其解密,然后将其发送至requests。问题是requests 只接受用于指定客户端密钥/证书的文件路径。我怎样才能让它接受一个字符串?
我想做的例子:
#X509
CLIENT_CERT_PATH = "path/to/cert" #perhaps I should convert this into a string too?
#PKey
CLIENT_PKEY_STRING = decrypt("path/to/encrypted_key")
response = requests.get(url = url, cert = (CLIENT_CERT_PATH, CLIENT_PKEY_STRING)) #how?
尝试
尝试了Python requests CA certificates as a string,但我得到了以下行为:AttributeError: module 'urllib3.contrib' has no attribute 'pyopenssl'。
还尝试了Example of including a certficate in a post request with python and http.client,甚至将其修改为:
class openSSLContext(requests.packages.urllib3.util.ssl_.SSLContext):
def __init__(self, method):
pk = crypto.load_privatekey(crypto.FILETYPE_PEM, open(CL_PKEY_PATH, "rb").read())
cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(CL_CERT_PATH, "rb").read())
requests.packages.urllib3.util.ssl_.SSLContext = openSSLContext
但我不知道从这里去哪里。
版本
Python 3.9.2
pyOpenSSL == 20.0.1
requests == 2.25.1
urllib3 == 1.26.4
【问题讨论】:
标签: python http ssl https python-requests