简体   繁体   English

python ssl问题打开证书文件

[英]python ssl issue opening certificate files

Here is my code: 这是我的代码:

import ssl
def main():
    context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    context.load_cert_chain(certfile=os.path.join('keys', 'server.crt'),
                            keyfile=os.path.join('keys', 'server.key'),
                            password="my certificate password")
    # more code to follow

if __name__ == '__main__':
    main()

I have confirmed that my two files look like: 我已经确认我的两个文件如下所示:

-----BEGIN RSA PRIVATE KEY-----
 # my key file
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
 # my cert file
-----END CERTIFICATE-----

It was hanging on the context.load_cert_chain(...) line. 它挂在context.load_cert_chain(...)行上。 No exceptions are thrown and it never returns. 没有异常抛出,它永远不会返回。 It turns out it was missing the password parameter (for the certificate) 原来它缺少密码参数(用于证书)

我已经编辑了代码,感谢Steffen Ullrich,添加了缺少的密码参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM