Error fix · Developer errors

Python CERTIFICATE_VERIFY_FAILED: Causes and Fixes

Fix Python's ssl.SSLCertVerificationError CERTIFICATE_VERIFY_FAILED in requests, urllib and pip by finding which trust store is broken and why.

Error messagessl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

By SiteDownCheck Editorial · Updated November 18, 2026 · 4 min read

Python raised this because it connected to an HTTPS server, received a certificate, and could not build a trusted path from it to a root certificate in the trust store Python is using. The text after "certificate verify failed:" tells you which of several problems you have, so read it before changing anything.

A typical traceback from the requests library looks like this:

requests.exceptions.SSLError: HTTPSConnectionPool(host='api.example.com', port=443):
Max retries exceeded with url: /v1/items (Caused by SSLError(SSLCertVerificationError(1,
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer
certificate (_ssl.c:1006)')))

With urllib or http.client you get ssl.SSLCertVerificationError directly, or urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] ...>. The _ssl.c line number varies by Python version.

Read the reason after the colon

Reason textMeaning
unable to get local issuer certificateThe chain is incomplete or your trust store lacks the issuing CA
self-signed certificateThe server's own certificate is its own issuer and not trusted
self-signed certificate in certificate chainSomething in the chain, often a proxy, is an untrusted private root
certificate has expiredA certificate in the chain is past its Not After date
Hostname mismatch, certificate is not valid for 'x'The name you requested is not in the SAN list

The hostname and expiry cases are not trust-store problems. See certificate name mismatch and ERR_CERT_DATE_INVALID.

Step 1: test the server without Python

Run the same URL with curl and openssl. If curl on the same machine succeeds, the server is fine and Python is using a different trust store.

curl -vI https://api.example.com/ 2>&1 | grep -iE "SSL|issuer|verify"
openssl s_client -connect api.example.com:443 -servername api.example.com </dev/null 2>/dev/null | grep -E "Verify return code|^ *[0-9] s:"

If openssl prints Verify return code: 21 (unable to verify the first certificate) or code 20, the server is sending an incomplete chain. Fix the server instead of every client: see incomplete certificate chain. Paste the hostname into the SSL Chain Debugger to confirm.

Step 2: find which CA bundle Python uses

Python's ssl module and requests do not necessarily share a bundle.

python3 -c "import ssl; print(ssl.get_default_verify_paths())"
python3 -c "import certifi; print(certifi.where())"
env | grep -iE "SSL_CERT|REQUESTS_CA|CURL_CA"
  • urllib, http.client, aiohttp (by default) use the OpenSSL default paths, usually the operating system store, and honor SSL_CERT_FILE and SSL_CERT_DIR.
  • requests uses the certifi package bundle unless REQUESTS_CA_BUNDLE or CURL_CA_BUNDLE is set.
  • A stale REQUESTS_CA_BUNDLE pointing at a deleted file or a bundle that lacks the public CAs is a common self-inflicted cause.

Fix by cause

Outdated certifi or OS store. Newer CAs and cross-signs will not be in an old bundle:

python3 -m pip install --upgrade certifi
sudo apt-get install --reinstall ca-certificates && sudo update-ca-certificates   # Debian/Ubuntu

macOS with python.org installer. That build ships without system roots wired in. Run the "Install Certificates.command" script in /Applications/Python 3.x/, which links Python to certifi.

Docker slim or Alpine images. Minimal images may have no CA bundle at all. Install ca-certificates in the image build.

Corporate TLS inspection or a private CA. If the issuer shown by openssl s_client -showcerts is your company's proxy or an internal CA, add that root to the bundle you actually use:

cat corp-root.pem >> "$(python3 -c 'import certifi; print(certifi.where())')"
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/corp-bundle.pem
export SSL_CERT_FILE=/etc/ssl/certs/corp-bundle.pem

Appending to certifi is overwritten on upgrade, so a separate bundle file plus an environment variable is more durable. Per call you can pass requests.get(url, verify="/path/to/bundle.pem").

pip itself fails. Use pip config set global.cert /path/to/bundle.pem or pip --cert /path/to/bundle.pem install pkg.

Server sends an incomplete chain. Browsers can fetch missing intermediates; Python will not. Configure the server to send the full chain.

Confirm the fix

python3 - <<'EOF'
import requests
r = requests.get("https://api.example.com/", timeout=10)
print(r.status_code)
EOF

A status code means the handshake verified. Also run the SSL Checker to confirm expiry and chain from outside your network, and put the endpoint under an uptime monitor so certificate trouble pages you before your scripts break.

Next steps

FAQ

Why does requests fail when curl works?

They use different CA bundles. curl uses the system store (or its own build default), while requests uses certifi. Update certifi or point REQUESTS_CA_BUNDLE at a bundle that contains the issuing CA.

Is it safe to set verify=False?

No, not outside a throwaway test. It disables server authentication, so a man-in-the-middle can read and alter the traffic.

Why did it start failing without any code change?

A certificate was renewed with a new intermediate, a root expired in an old bundle, or a proxy or antivirus began intercepting TLS. Check the issuer with openssl first.

Does it matter that I am on Python 3.12 or 3.13?

The error text is the same across modern versions. What changes between versions is the default verification flags, so an old private CA that lacks certain extensions may fail on newer Python; reissue it if so.

Get notified when this fix updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.