Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPSConnectionPool: Max retries exceeded with URL (Caused by SSLError)

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.

like image 839
gapanihu Avatar asked Sep 16 '25 21:09

gapanihu


1 Answers

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.

like image 81
4x0t Avatar answered Sep 19 '25 13:09

4x0t