I’m trying to access an endpoint, which requires a client cert. I’m starting from a .p12, which I was able to quickly import to Google Chrome, and can successfully access the endpoint. So the client certificate and endpoint are compatible.
However, I’m struggling to get Python Requests module (with Python 2.7) to successfully access the same endpoint.
My steps have been:
openssl pkcs12 -in my.p12 -out certificate.pem –nodes
prompts me for a password, then creates certificate.pemprint(requests.get("<https://endpoint>", cert="certificate.pem").content)
returns You don't have permission to access "http" on this server. (and a HTTP response of 403)My PEM file contains three sets of -----BEGIN CERTIFICATE-----
, and then -----BEGIN PRIVATE KEY-----
.
All 4 BEGINs are preceded by Bag Attributes – removing these lines doesn’t make a difference.
I'm doing the key creation with a Ubuntu VM, but running the Python from a Windows machine - not sure if this makes a difference.
I’d welcome any ideas; particularly to understand if the issue is around the conversion to PEM, or if it’s with the request call.
I found https://gist.github.com/erikbern/756b1d8df2d1487497d29b90e81f8068, with the delete=False
param as suggested in those comments, and pyOpenSSL, now works.