简体   繁体   中英

Can't send a request, OpenSSL key and cert error

I have different error output for Linux and Windows (both use python 3.7.3 and PyOpenSSL 19.0).


response = s.post(url=my_url,
                 data=json.dumps(data.__dict__), 
                 timeout=15,
                 headers={'accept': 'application/json', 'content-type':'application/json'}, 
                 cert=(str(Path(__file__).parents[1]) + "/my_key.key",str(Path(__file__).parents[1]) + "/my_cert.crt"),
                 verify=False)

And I've installed OpenSSL and wrappers for Python on both systems.

On Windows: OpenSSL.SSL.Error: [('PEM routines', 'get_name', 'no start line'), ('SSL routines', 'use_certificate_chain_file', 'PEM lib')]

On Linux [('PEM routines', 'get_name', 'no start line'), ('SSL routines', 'SSL_CTX_use_PrivateKey_file', 'PEM lib')]

And I'm sure that cert and key are OK, because I've tried a curl request.

What causes this error?

Your certificate and key files are in the incorrect format. From the error, it looks like it wants a the certificate and key in the PEM format.

My guess is that your certificate and key are in DER format. Try converting the files from DER to PEM.

See https://serverfault.com/questions/254627/how-do-i-convert-a-cer-certificate-to-pem as a example of how to convert CER to PEM format.

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