Fix Python SSL CERTIFICATE_VERIFY_FAILED on Linux (requests, pip, uv, git)

, ,
Fix Python SSL CERTIFICATE_VERIFY_FAILED on Linux (requests, pip, uv, git)

[SSL: CERTIFICATE_VERIFY_FAILED] is one of the most common errors in Python on Linux, and it rarely means the code is wrong. It means a TLS client could not build a chain from the server’s certificate to a root it trusts. The confusing part is that Python, requests, pip, uv, git, and curl do not all use the same list of trusted roots, so one tool can fail while another works against the same server.

This guide shows how to find which trust store each tool is using, how to update it, how to add a private or corporate CA correctly, and why you should not “fix” the error by turning verification off. All error messages below were reproduced on Debian 13 with Python 3.13 against a test server with an untrusted root.

Quick fix: Update the trust stores first: sudo apt install --reinstall ca-certificates and python -m pip install -U certifi inside your environment. For a corporate CA, copy it to /usr/local/share/ca-certificates/corp.crt, run sudo update-ca-certificates, and point Python tools at /etc/ssl/certs/ca-certificates.crt with REQUESTS_CA_BUNDLE or SSL_CERT_FILE.

What does the error look like in each tool?

# Python standard library (urllib)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1029)>

# requests
requests.exceptions.SSLError: HTTPSConnectionPool(host='...', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1029)')))

# pip
Could not fetch URL https://.../simple/requests/: There was a problem confirming the ssl certificate: ... CERTIFICATE_VERIFY_FAILED ...

# git (Debian builds use GnuTLS)
fatal: unable to access 'https://...': server verification failed: certificate signer not trusted. (CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none)

# curl
curl: (60) SSL certificate problem: self-signed certificate in certificate chain

The text after certificate verify failed: is the useful part. self-signed certificate in certificate chain or unable to get local issuer certificate means the root is not in the store that tool uses. certificate has expired points to the server, or to a wrong system clock.

Why did this start failing recently? The eMudhra distrust

Trust stores change. In October 2026, a researcher reported that eight eMudhra TLS intermediate CAs chaining to the emSign ECC Root CA – G3 had been generated with weak keys. eMudhra revoked the intermediates and stated that no certificates had been issued from them and that its infrastructure was not compromised. Browser and operating system root programs removed trust in the ECC G3 root during the following days.

The Python certifi package, which requests and many other libraries use as their CA bundle, went through several releases: 2026.10.18 removed all four emSign roots, a later release restored some, and 2026.10.23 left only emSign Root CA – G1. GitHub published advisory GHSA-6q48-6c7w-9gw2 for older certifi versions.

This kind of change cuts both ways:

  • Updated bundle, failing site: a server whose chain ends at a removed root now fails with CERTIFICATE_VERIFY_FAILED. The fix belongs to the site operator, who needs a certificate from a trusted CA. Do not add the removed root back.
  • Stale bundle, silent risk: an old certifi pinned in a lockfile or baked into a container image keeps trusting a root that everyone else dropped. Nothing fails, which is exactly the problem.

Note: Check eMudhra’s statement and the GitHub advisory for the latest details. The practical takeaway does not depend on them: keep certifi and ca-certificates current, and rebuild container images after trust store updates.

Which trust store does each tool use?

Diagram mapping Python ssl, requests, pip, uv, git and curl to the system CA store, certifi, or uv bundled roots, with override options
Which trust store each tool reads by default, and how to override it.
ToolDefault trust storeOverride
Python ssl, urllibOpenSSL defaults (Debian/Ubuntu: /usr/lib/ssl/cert.pem → system bundle)SSL_CERT_FILE, SSL_CERT_DIR
requestscertifi bundle inside the environmentREQUESTS_CA_BUNDLE, or verify=
pip 24.2+ on Python 3.10+System store (via truststore) plus certifi--cert, PIP_CERT, pip config set global.cert
uvBundled Mozilla roots--system-certs / UV_SYSTEM_CERTS=true, SSL_CERT_FILE
gitSystem bundlehttp.sslCAInfo
curlSystem bundle--cacert, CURL_CA_BUNDLE

This table explains most “works in curl, fails in Python” reports: curl reads the system bundle, while requests reads certifi, so a CA added with update-ca-certificates helps curl but not requests.

Step 1: How do you find which bundle Python is using?

  1. Print the OpenSSL defaults and the certifi path from the same interpreter that fails:
    python -c "import ssl; print(ssl.get_default_verify_paths())"
    python -c "import certifi; print(certifi.where(), certifi.__version__)"
    DefaultVerifyPaths(cafile='/usr/lib/ssl/cert.pem', capath='/usr/lib/ssl/certs', openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/usr/lib/ssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/usr/lib/ssl/certs')
    /usr/local/lib/python3.13/dist-packages/certifi/cacert.pem 2026.10.23

    You should see two different locations. If certifi is older than 2026.10.23, update it.

  2. See what the server actually sends:
    openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | grep -E "s:|i:"

    You should see each certificate’s subject (s:) and issuer (i:). The last issuer is the root your store must contain. If the server omits an intermediate, the fix is on the server.

Step 2: How do you update the trust stores?

  1. Update the system bundle and certifi:
    sudo apt update && sudo apt install --reinstall ca-certificates
    python -m pip install -U certifi        # inside the venv
    uv lock --upgrade-package certifi       # uv projects

    You should see certifi at 2026.10.23 or newer in uv.lock or pip show certifi.

  2. Rebuild container images rather than patching running containers, so the new bundle ends up in every deployment.

Step 3: How do you trust a private or corporate CA?

Corporate proxies that inspect TLS re-sign traffic with their own root. Add that root to the system store once, then point the Python tools at the system bundle.

  1. Install the CA into the system store. The file must be PEM and end in .crt:
    sudo cp corp-root.pem /usr/local/share/ca-certificates/corp-root.crt
    sudo update-ca-certificates
    Updating certificates in /etc/ssl/certs...
    1 added, 0 removed; done.

    You should see 1 added. Fedora and RHEL use /etc/pki/ca-trust/source/anchors/ and sudo update-ca-trust instead.

  2. Point each tool at the updated bundle:
    export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt   # requests
    export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt        # ssl, urllib, uv
    pip config set global.cert /etc/ssl/certs/ca-certificates.crt  # pip
    export UV_SYSTEM_CERTS=true                                    # uv, alternative
    git config --global http.sslCAInfo /etc/ssl/certs/ca-certificates.crt

    You should see the original request succeed. In our test, git -c http.sslCAInfo=... and curl --cacert ... connected once given the right CA.

Tip: Point REQUESTS_CA_BUNDLE at the full system bundle, not at a file containing only the corporate root. These variables replace the default store, so a single-certificate file breaks every other HTTPS site.

To scope git to one server, use a URL-specific key such as git config --global http.https://git.corp.example.com/.sslCAInfo /path/to/corp-root.pem.

Why does Python 3.13 reject a CA that curl accepts?

Python 3.13 turned on stricter X.509 checks in ssl.create_default_context() (VERIFY_X509_STRICT). Older private CAs that lack required extensions now fail even when they are trusted. In our test, a legacy test root without an Authority Key Identifier produced:

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Missing Authority Key Identifier (_ssl.c:1029)

curl and git accepted the same CA. The right fix is to reissue the internal CA with standard extensions. As a short-term workaround for one internal client, you can create a context and clear only that flag with ctx.verify_flags &= ~ssl.VERIFY_X509_STRICT, keeping verification on.

Why shouldn’t you disable verification?

Snippets like verify=False, --trusted-host, git config http.sslVerify false, or PYTHONHTTPSVERIFY=0 make the error disappear by accepting any certificate. Anyone on the network path can then impersonate the server, and for package installs that means running their code on your machine.

Warning: Never disable TLS verification in CI, Dockerfiles, or shared configuration. If you must test against a lab server, trust its specific CA file instead, as shown in Step 3.

What else causes CERTIFICATE_VERIFY_FAILED?

Message detailLikely causeFix
unable to get local issuer certificateMissing intermediate or unknown rootCheck the chain with s_client; update or add the CA
certificate has expiredExpired certificate or wrong system clockCheck timedatectl; renew the certificate
Hostname mismatchWrong host name or SNIUse the name in the certificate
Works on host, fails in DockerImage has old or no ca-certificatesInstall and update it in the image
Works in curl, fails in requestscertifi vs system storeSet REQUESTS_CA_BUNDLE or use truststore

FAQ

Should I use certifi or the system store?

On a managed Linux machine, the system store is usually better because your administrators and distribution update it. The truststore package lets Python code use the system store, and pip already does this by default.

Does pip install --upgrade certifi fix git or curl?

No. certifi only affects Python code that uses it. git and curl use the system bundle.

Is --trusted-host safe on an internal network?

It skips verification for that host, so it is only as safe as your network. Trusting the internal CA is the safer fix.

Conclusion

Find which store the failing tool reads, update certifi and ca-certificates, add private CAs through update-ca-certificates, and point requests, pip, uv, and git at the system bundle. Keep verification on, and rebuild images when trust stores change.

Related guides

Official references

Leave a Reply