Skip to content
MtrXTools

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

Python couldn't verify the server's certificate

Seen in Python ssl, requests, urllib3, httpx, aiohttp, urllib (ssl.SSLCertVerificationError)

Python could not verify the server certificate; the text after "certificate verify failed:" gives the exact reason.

Common causes

  • "unable to get local issuer certificate": the server omits its intermediate, or Python cannot find a CA bundle (common with python.org builds on macOS).
  • A corporate proxy or antivirus re-signs HTTPS traffic with a CA that certifi does not include.
  • "certificate has expired" or "self-signed certificate": the server certificate itself is the problem.
  • An outdated certifi package or OS CA store.

How to fix it

  1. Update the CA bundle: pip install --upgrade certifi; on macOS python.org installs, run "Install Certificates.command".
  2. For a corporate CA, set REQUESTS_CA_BUNDLE or SSL_CERT_FILE to a PEM file that includes it, or use the truststore package to use the OS trust store.
  3. If the server omits its intermediate, fix the server to send the full chain.
  4. verify=False only hides the problem and is not a fix.
Check whether the chain is complete

Got a different message? Paste it into the error explainer.

Related errors

All 32 Languages & runtimes errors