我正在尝试使用PEM文件和httplib
连接到带有python客户端的HTTPS WS这是代码
# HTTPS connection with python
#!/usr/bin/env python
import httplib , urllib
CERTFILE = 'path_to_pem_file'
hostname = 'IP_address:Port_number'
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
Json_data = {
"amountTransaction": {
some json data ..
}
}
params = urllib.urlencode(Json_data)
conn = httplib.HTTPSConnection(
hostname,
key_file = CERTFILE,
cert_file = CERTFILE
)
conn.request("POST", '/url_to_call', params, headers)
print conn.getreponse().read()
print response.status, response.reason
conn.close()
但我收到以下错误信息,
SSLError: [Errno 336265225] _ssl.c:354: error:140B0009:SSL
routines:SSL_CTX_use_PrivateKey_file:PEM lib
请你检查一下
是什么错误答案 0 :(得分:1)
cert_file
和key_file
用于针对服务器的客户端身份验证,并且必须包含证书和匹配的私钥。我会解释错误消息,即PEM文件中没有密钥,它与证书不匹配或者受密码保护,因此无法读取。