简体   繁体   中英

How do I use a .cer file as part of a python request

Say that I have a cer file called symantec-class3.cer, this is what I'm trying:

headers = {"content-type": "application/json"}
api_url = "https://www.someurl.com/search"
pprint.pprint(requests.post(api_url, auth=HTTPBasicAuth(username, password), verify="symantec-class3.cer", data=json.dumps(payload), headers=headers).json())

This is not liking it and spews out the following error:

requests.exceptions.SSLError: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)

It works fine if I turn verify False, but I'm trying to use a cert file in my local directory.

Python expect cert in PEM format.

So you should extract the public key component from the X509 certificate using the openssl x509 command.

.cer extension often means a binary DER format, so this command should extract the public key in a form that can be used by pycrypto:

openssl x509 -inform der -pubkey -noout -in you.cer >public_key.pem

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