简体   繁体   中英

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. No exceptions are thrown and it never returns. It turns out it was missing the password parameter (for the certificate)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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