Python Requests: Ignore SSL Certificate Errors, and the Right Way

Rewritten as a tested reference. Every call shown below was executed by the example package against a local HTTPS server with a self-signed certificate; the output blocks are what it printed (see "How the outputs were captured"). Four recipes from the 2024 version were wrong and are shown failing here: passing an ssl.SSLContext as verify=, REQUESTS_CA_BUNDLE="", "verify=False disables verification globally", and the "certificate pinning" example built on the same invalid verify= call.
You called requests.get() and got this:
requests.exceptions.SSLError: HTTPSConnectionPool(host='localhost', port=8443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1010)')))
The two-line way to make it go away:
import requests, urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
response = requests.get("https://localhost:8443/", verify=False)
And the one-line way to fix it instead of hiding it, when you have the server's certificate or your company's CA file:
response = requests.get("https://localhost:8443/", verify="certs/localhost.pem")
The rest of this page shows what each option does, with the real output, including the recipes you will find elsewhere that do nothing or crash in current requests.








