I am trying to make an HTTPS request to a URL using Python requests library and certifi library as follows:
import certifi
url = 'https://10.0.0.39:4455/api/cars'
response = requests.get(url, verify=certifi.where())
if response.status_code == 200:
print(response.json())
else:
print(f'Request failed with status code {response.status_code}: {response.text}')
However, I keep getting the following error message:
"requests.exceptions.SSLError: HTTPSConnectionPool(host='https://10.0.0.39/api/cars', port=4455):
Max retries exceeded with url: /api/cars (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))"
I have already imported the certifi module to verify the SSL/TLS certificate. I have also installed the certifi module using pip. However, I am still getting this error message. How can I resolve this issue? also, the flask api is running on my other computer(10.0.0.39) and have an ssl certificat active.
If you add verify=False to your requests.get() call and the error went away, it is likely that the SSL certificate issued by the server is not trusted on your client. To fix this, you can either use a trusted certificate from a recognized certificate authority on the API end, or add the certificate authority from your API to your client. if the error stay, try these commands to update your certifi libs
pip install --upgrade certifi
if older version of python3
python -m pip install --upgrade certifi
if newer version of python3
This will ensure that your client has the latest version of the library, which includes a set of trusted root certificates that may be needed to verify SSL certificates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With