Learn Python: How to ignore SSL verification for HTTP requests

When you are testing any web apis on your local development machine, you most probably have a self signed certificate for all HTTPS requests. When you will call these apis using requests Python package, you are going to see following excepttion.

Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)')))

There is an easy solution to this problem. requests package allows you to pass additional parameter to ignore SSL verification. For GET request, pass verify parameter with False value. Your code will look like below.

response = requests.get(apiUrl, verify=False)

This request will work as you expected. If you are logging warning or messages in console, you will see following warning about insecure request.

InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings

Make sure that you do not ignore SSL check for production deployment.




17.2 °C / 62.9 °F

weather conditions Clear

Monthly Posts

Blog Tags