visit
I was stuck at a point and learning what I did to fix that issue was great and led me to create a post ondeep dive with SSL certificates.
response = requests.post(url, files=files, headers=headers)
/ (Caused by SSLError(SSLCertVerification(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)'))
My first try was to use the verify flag as False
and try.
response = requests.post(url, files=files, headers=headers, verify=False)
response = requests.post(url, files=files, headers=headers, verify='server.cer')
This is a DER encoded certificate
/ (Caused by SSLError(SSLError(136, '[X509] no certificate or crl found (_ssl.c:4232)'))
The module requests to use certifi to access the CA bundle and validate secure SSL connections and we can use the CA_REQUESTS_BUNDLE environment variable to override the CA bundle location. So I thought, if I can manually provide the server.cer in that variable, I will achieve enlightenment. But to my despair, that too failed.
Then I thought that the requests module must not be taking the DER encoded certificate. So I converted to PEM which is plaintext but Base 64 encoded.
openssl x509 -in server.cer -inform DER -outform PEM -out server.pem
response = requests.post(url, files=files, headers=headers, verify='server.pem')
/ (Caused by SSLError(SSLCertVerification(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)'))
Yes, this is the same as Error 1. So we are back to square 1. I tried to search the internet, but no one had a meaningful solution. Someone
Then I thought this is not the way, I will solve this issue. So I did a lot of studying for the Certificates and finally, I got them. I wrote the Deep Dive article and put everything there.
Root CA signs → intermediate CA
Intermediate CA signs → server certificate
unable to get local issuer certificate (_ssl.c:1108)
This is done in windows but, similar things can be done in Mac or Linux.
Now, all we have to do is to convert all these .cer files to .pem files and add them together to create a consolidated pem file and feed it to python requests.
openssl x509 -in server.cer -inform DER -outform PEM >> consolidate.pem
All we are doing it here is to create a full fledged CA bundle which has all the certificates and anyway we can do it, is just fine.
response = requests.post(url, files=files, headers=headers, verify='consolidate.pem')<Response [200]>