Fix pip SSL: CERTIFICATE_VERIFY_FAILED behind a proxy
pip SSL: CERTIFICATE_VERIFY_FAILED means pip doesn't trust your proxy's or private index's CA. Check the issuer, then add it to the OS store, --cert, PIP_CERT.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1011)'))': /simple/six/…Could not fetch URL https://localhost:8443/simple/six/: There was a problem confirming the ssl certificate: …ERROR: Could not find a version that satisfies the requirement six (from versions: none)ERROR: No matching distribution found for sixpip could not chain the index server's certificate to a CA it trusts. It happens when a corporate proxy re-signs HTTPS traffic or an internal index uses a certificate from a private CA. Give pip that CA certificate and it goes away. The last two lines match No matching distribution found, so look for the WARNING: Retrying … CERTIFICATE_VERIFY_FAILED lines above them. The tests below recreate the situation with an index at https://localhost:8443 signed by a private CA.
[1] Check who signed the certificate. If the issuer (i:) is your company or a security product rather than a public CA, the proxy re-signed it.
$ openssl s_client -connect localhost:8443 -servername localhost < /dev/null 2>/dev/null | grep -E '^ *[0-9] s:|^ *i:|Verify return code' 0 s:CN=localhost i:CN=Example Corp Proxy CAVerify return code: 21 (unable to verify the first certificate)On a real network, check pypi.org:443 or files.pythonhosted.org:443 instead of localhost:8443. Get the CA certificate (a PEM file) from your IT team. A file exported from a browser also works, but confirm whose CA it is before you trust it.
[2] Check the pip version. According to the pip docs, pip 24.2 and later use the OS certificate store (through truststore) alongside the certifi bundle. Older releases do not use system certificates by default (certifi only), so they ignore a CA you added to the OS. The same page says pip 22.2 and later can opt in with --use-feature=truststore (not tested here).
$ python --version; python -m pip --versionPython 3.12.16pip 25.0.1 from /usr/local/lib/python3.12/site-packages/pip (python 3.12)Below 24.2, run python -m pip install --upgrade pip first. If the certificate error blocks that too, add the --cert option from [4] to the upgrade.
[3] Add the CA to the OS store. With pip 24.2 or later, nothing else is needed. This is Debian/Ubuntu, tested inside the container.
# cp /srv/pki/ca.pem /usr/local/share/ca-certificates/example-proxy-ca.crt && update-ca-certificates 2>&1 | tail -1$ python -m pip install --no-cache-dir --index-url https://localhost:8443/simple/ sixdone.Looking in indexes: https://localhost:8443/simple/Collecting six Downloading https://localhost:8443/simple/six/six-1.16.0-py2.py3-none-any.whl (11 kB)Installing collected packages: sixSuccessfully installed six-1.16.0Per the update-ca-certificates man page, the file must be PEM with a .crt extension to be picked up. The OS store is shared by other programs on the machine (curl, apt and so on), so agree with the admin before adding it on a shared server. Before copying, check ls /usr/local/share/ca-certificates/ for a file with the same name (pick another name if there is one — overwriting it removes the original CA). To roll back, delete only the file you added and run sudo update-ca-certificates again. In the same test, adding --use-deprecated=legacy-certs (which stops pip from using the OS store) made the install fail again.
[4] If you cannot touch the OS store, hand the CA file to pip only. All three of these passed:
| Method | Scope |
|---|---|
--cert /path/ca.pem | One command |
PIP_CERT=/path/ca.pem | One shell or CI job |
pip config --user set global.cert /path/ca.pem | Every pip run for that user (~/.config/pip/pip.conf) |
$ python -m pip config --user set global.cert /srv/pki/ca.pem$ python -m pip config listWriting to /root/.config/pip/pip.conf…global.cert='/srv/pki/ca.pem'global.cert stays in that user's config file. Before setting it, note any existing value with python -m pip config get global.cert; to roll back, set that value again or, if there was none, remove it with python -m pip config --user unset global.cert.
The pip docs describe --cert as a CA bundle that "overrides the default". If you also use other indexes that do not go through the proxy, give it a public CA bundle with your company CA appended, not the company CA alone. REQUESTS_CA_BUNDLE is in the pip docs too and passed in the test, but it also affects every other Python program using requests, so use PIP_CERT when only pip should change.
[5] Do not get past it with --trusted-host. The pip docs describe it as marking a host trusted "even though it does not have valid or any HTTPS". In the test it accepted a certificate from an unknown CA and installed.
$ python -m pip install --no-cache-dir --index-url https://localhost:8443/simple/ --trusted-host localhost sixLooking in indexes: https://localhost:8443/simple/Collecting six Downloading https://localhost:8443/simple/six/six-1.16.0-py2.py3-none-any.whl (11 kB)Installing collected packages: sixSuccessfully installed six-1.16.0A server impersonating that name could hand you different packages and pip would install them. If pip.conf or requirements.txt still has a line like --trusted-host pypi.org, remove it and switch to [3] or [4]. Afterwards pip config list should show no trusted-host.
If curl fails against the same server with unable to get local issuer certificate, the server may be missing its intermediate certificate. Sort out the chain with curl unable to get local issuer certificate.
Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.