How to Fix Python SSL: CERTIFICATE_VERIFY_FAILED Errors
Python's SSL: CERTIFICATE_VERIFY_FAILED means the check Python makes before it sends anything failed, and the words after the colon say which part. On a real Ubuntu PC we fix the common causes: a server signed by your company's own certificate authority (and why adding it to Ubuntu's list fixes curl but not requests), pip failing behind an office network that inspects HTTPS, an expired certificate and a hostname mismatch, and why verify=False is not a fix.
The error and the words after the colon
Your Python script stops with an SSL error: certificate verify failed. By the end, you'll know which fix your error needs, and why turning the check off is the one to avoid. Chris's script sends the milk tank's temperature from his family's dairy farm to the co-op, and today it stopped.
(.venv) chris@farm-pc:~/milk-tank$ python send_reading.pyTraceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 470, in _make_request self._validate_conn(conn) File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1125, in _validate_conn conn.connect() File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 878, in connect wrapped_socket, is_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 1080, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrap_socket( ^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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 "/home/chris/milk-tank/.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: unable to get local issuer certificate (_ssl.c:1000) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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: unable to get local issuer certificate (_ssl.c:1000) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 696, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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='portal.coop.lan', port=443): Max retries exceeded with url: /api/readings (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)'))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/send_reading.py", line 6, in <module> r = requests.post(URL, json=reading, timeout=10) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 134, in post return request("post", url, data=data, json=json, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 71, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 651, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 784, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 727, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='portal.coop.lan', port=443): Max retries exceeded with url: /api/readings (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')))
The traceback is seventy-one lines long. Only the last one matters, after the colon: unable to get local issuer certificate. Those words tell you where to fix it, and we'll see three different reasons before we're done.

What Python checks
Those words come from a check Python makes before it sends anything. The co-op's server answers with its certificate, a small file that says: I am portal.coop.lan, and this authority vouches for me. Python looks for that authority on its list of trusted ones. It's not there. Unable to get local issuer certificate means just that: the issuer, the authority that signed it, isn't on Python's list.

Think of a shop till that takes gift cards only from the brands on a list taped beside it. Bring a card from the dairy co-op's own farm store, and the till refuses it, even though the card is real. It just isn't on that till's list.

Quick fix: name the co-op's CA file
The usual fix is to tell Python which authority to trust. The co-op runs its own certificate authority, a CA for short, and it emailed Chris the CA's file. Chris's script uses a library called requests. requests checks a setting named REQUESTS_CA_BUNDLE. You give it the path to a file of authorities to trust. Set it in front of the command, point it at the co-op's file, and the reading is sent.
(.venv) chris@farm-pc:~/milk-tank$ ls ~/Downloadscoop-root-ca.crt
(.venv) chris@farm-pc:~/milk-tank$ REQUESTS_CA_BUNDLE=~/Downloads/coop-root-ca.crt python send_reading.pyReading sent: {'saved': True, 'tank': 1}
But there's a catch. Chris's other scripts fetch from public sites, like pypi.org. Guess first: with that variable still set, does pypi.org work? No. Same words. The variable doesn't add the co-op to the list requests already has. It replaces that whole list, and the co-op's file holds just one authority. Without the variable, pypi.org answers 200 OK. So Chris needs a list with both.
(.venv) chris@farm-pc:~/milk-tank$ REQUESTS_CA_BUNDLE=~/Downloads/coop-root-ca.crt python fetch.py https://pypi.orgTraceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 470, in _make_request self._validate_conn(conn) File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1125, in _validate_conn conn.connect() File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 878, in connect wrapped_socket, is_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 1080, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrap_socket( ^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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 "/home/chris/milk-tank/.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: unable to get local issuer certificate (_ssl.c:1000) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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: unable to get local issuer certificate (_ssl.c:1000) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 696, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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='pypi.org', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)'))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/fetch.py", line 7, in <module> r = requests.get(url, timeout=10, verify=check) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 87, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 71, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 651, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 784, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 727, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')))
(.venv) chris@farm-pc:~/milk-tank$ python fetch.py https://pypi.org200 OK
Adding the CA to Ubuntu's list
Most guides say: add the authority to the computer's own list. curl, the command line download tool, uses that list, and right now it fails the same way. On Ubuntu, copy the file into this folder, then run update-ca-certificates, both with sudo, as the administrator. One added. curl now gets the co-op's answer. Guess first: does Chris's Python script work now? It doesn't. Same error, same words.
(.venv) chris@farm-pc:~/milk-tank$ curl https://portal.coop.lan/api/readingscurl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.
(.venv) chris@farm-pc:~/milk-tank$ sudo cp ~/Downloads/coop-root-ca.crt /usr/local/share/ca-certificates/
(.venv) chris@farm-pc:~/milk-tank$ sudo update-ca-certificatesUpdating certificates in /etc/ssl/certs... rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL 1 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... done.
(.venv) chris@farm-pc:~/milk-tank$ curl https://portal.coop.lan/api/readings{"saved": true, "tank": 1}
(.venv) chris@farm-pc:~/milk-tank$ python send_reading.pyTraceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 470, in _make_request self._validate_conn(conn) File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1125, in _validate_conn conn.connect() File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 878, in connect wrapped_socket, is_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 1080, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrap_socket( ^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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 "/home/chris/milk-tank/.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: unable to get local issuer certificate (_ssl.c:1000) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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: unable to get local issuer certificate (_ssl.c:1000) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 696, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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='portal.coop.lan', port=443): Max retries exceeded with url: /api/readings (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)'))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/send_reading.py", line 6, in <module> r = requests.post(URL, json=reading, timeout=10) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 134, in post return request("post", url, data=data, json=json, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 71, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 651, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 784, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 727, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='portal.coop.lan', port=443): Max retries exceeded with url: /api/readings (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')))
So where does requests look? requests.certs.where prints it: a file inside the virtual environment, the project's own private folder of packages, from a package called certifi. Count the authorities in each file: 113 in certifi's, 121 in Ubuntu's, now including the co-op's. Two tills, two lists, and Chris added the co-op to the list on the wrong till.
(.venv) chris@farm-pc:~/milk-tank$ python -c 'import requests; print(requests.certs.where())'/home/chris/milk-tank/.venv/lib/python3.12/site-packages/certifi/cacert.pem
(.venv) chris@farm-pc:~/milk-tank$ grep -c 'BEGIN CERT' $(python -m certifi) /etc/ssl/certs/ca-certificates.crt/home/chris/milk-tank/.venv/lib/python3.12/site-packages/certifi/cacert.pem:113 /etc/ssl/certs/ca-certificates.crt:121
The requests documentation says so in its first line on the subject: Requests uses certificates from the package certifi. Not from your operating system.

So point the same variable at Ubuntu's whole list instead. The path is on screen. Use export, so it stays set for this whole window. Now the reading is sent, and pypi.org answers too, because that one file holds both.
(.venv) chris@farm-pc:~/milk-tank$ export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
(.venv) chris@farm-pc:~/milk-tank$ python send_reading.pyReading sent: {'saved': True, 'tank': 1}
(.venv) chris@farm-pc:~/milk-tank$ python fetch.py https://pypi.org200 OK
truststore: Python uses the system's list
But close this window, and tomorrow morning the reading fails again, because a variable only lasts while it's set. The tidier fix is a package called truststore. It makes Python use the operating system's own list instead of certifi's. It works on Linux, Windows and macOS. You need Python 3.10 or newer. Chris installs it with pip.
(.venv) chris@farm-pc:~/milk-tank$ unset REQUESTS_CA_BUNDLE
(.venv) chris@farm-pc:~/milk-tank$ pip install truststoreCollecting truststore Downloading truststore-0.10.5-py3-none-any.whl.metadata (4.5 kB) Downloading truststore-0.10.5-py3-none-any.whl (19 kB) Installing collected packages: truststore Successfully installed truststore-0.10.5
Then he adds two lines at the very top of his script, before requests is imported. Import truststore. Then truststore.inject_into_ssl. From here on, Python uses the system's list.

Run it, and the reading goes through with no variable at all. The co-op's certificate authority now lives in one place, Ubuntu's list, and both curl and this script find it there.
(.venv) chris@farm-pc:~/milk-tank$ python send_reading.pyReading sent: {'saved': True, 'tank': 1}
pip behind the office's inspection proxy
Now Sarah, at the co-op office. She makes a fresh virtual environment, and pip install requests fails: five retries, then the same words, unable to get local issuer certificate. But pypi.org's certificate is fine: Chris's farm PC just fetched it. So who signed what Sarah got? openssl, a command line tool that reads certificates, shows the issuer: the co-op's own Office Inspection CA.
(.venv) sarah@office-laptop:~/milk-tank$ pip install requestsWARNING: 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:1000)'))': /simple/requests/ WARNING: Retrying (Retry(total=3, 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:1000)'))': /simple/requests/ WARNING: Retrying (Retry(total=2, 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:1000)'))': /simple/requests/ WARNING: Retrying (Retry(total=1, 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:1000)'))': /simple/requests/ WARNING: Retrying (Retry(total=0, 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:1000)'))': /simple/requests/ Could not fetch URL https://pypi.org/simple/requests/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/requests/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)'))) - skipping ERROR: Could not find a version that satisfies the requirement requests (from versions: none) ERROR: No matching distribution found for requests
(.venv) sarah@office-laptop:~/milk-tank$ echo | openssl s_client -proxy proxy.coop.lan:8080 -connect pypi.org:443 2>/dev/null | openssl x509 -noout -issuerissuer=O = Valley Dairy Co-op, CN = Valley Dairy Co-op Office Inspection CA
The office network checks all outgoing traffic. Its inspection proxy opens each HTTPS connection, looks inside, and hands Sarah a new certificate it signed itself. To her laptop, that signer is a stranger, so this time the problem is on her side of the network, not on the server.

The office's IT team hands out that authority's file. Sarah adds it to Ubuntu's list, the same two commands as Chris, and pip install requests works.
(.venv) sarah@office-laptop:~/milk-tank$ sudo cp ~/Downloads/office-proxy-ca.crt /usr/local/share/ca-certificates/
(.venv) sarah@office-laptop:~/milk-tank$ sudo update-ca-certificatesUpdating certificates in /etc/ssl/certs... rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL 1 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... done.
(.venv) sarah@office-laptop:~/milk-tank$ pip install requestsCollecting requests Downloading requests-2.34.2-py3-none-any.whl.metadata (4.8 kB) Collecting charset_normalizer<4,>=2 (from requests) Downloading charset_normalizer-3.5.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.metadata (46 kB) Collecting idna<4,>=2.5 (from requests) Downloading idna-3.20-py3-none-any.whl.metadata (7.2 kB) Collecting urllib3<3,>=1.26 (from requests) Downloading urllib3-2.8.0-py3-none-any.whl.metadata (7.4 kB) Collecting certifi>=2023.5.7 (from requests) Downloading certifi-2026.11.20-py3-none-any.whl.metadata (2.5 kB) Downloading requests-2.34.2-py3-none-any.whl (73 kB) Downloading certifi-2026.11.20-py3-none-any.whl (127 kB) Downloading charset_normalizer-3.5.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (246 kB) Downloading idna-3.20-py3-none-any.whl (69 kB) Downloading urllib3-2.8.0-py3-none-any.whl (135 kB) Installing collected packages: urllib3, idna, charset_normalizer, certifi, requests Successfully installed certifi-2026.11.20 charset_normalizer-3.5.2 idna-3.20 requests-2.34.2 urllib3-2.8.0
That worked because pip reads the system's list. Ubuntu's own pip does this. And pip's documentation says that since version 24.2, every pip checks the system's list as well as certifi's.

Expired, or the wrong name
Not every reason after the colon is about a list. Chris's older script still posts to the co-op's old address, tank.coop.lan. There, the reason is: certificate has expired. openssl shows its end date: the first of October 2026. No setting on the farm PC fixes that. The co-op has to renew it, or Chris moves the script to the current address.
(.venv) chris@farm-pc:~/milk-tank$ python fetch.py https://tank.coop.lanTraceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 470, in _make_request self._validate_conn(conn) File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1125, in _validate_conn conn.connect() File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 878, in connect wrapped_socket, is_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 1080, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrap_socket( ^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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 "/home/chris/milk-tank/.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 "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/truststore/_api.py", line 134, in wrap_socket ssl_sock = self._ctx.wrap_socket( ^^^^^^^^^^^^^^^^^^^^^^ 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 "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/truststore/_api.py", line 109, in do_handshake ret = super().do_handshake(block) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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: certificate has expired (_ssl.c:1000) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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: certificate has expired (_ssl.c:1000) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 696, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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='tank.coop.lan', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1000)'))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/fetch.py", line 9, in <module> r = requests.get(url, timeout=10, verify=check) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 87, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 71, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 651, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 784, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 727, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='tank.coop.lan', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1000)')))
(.venv) chris@farm-pc:~/milk-tank$ echo | openssl s_client -connect tank.coop.lan:443 2>/dev/null | openssl x509 -noout -enddatenotAfter=Oct 1 00:00:00 2026 GMT
And this one. Chris types just portal, a short name his network also answers to. Hostname mismatch: the certificate is for portal.coop.lan, not portal. Use the full name that's on the certificate, and it's 200 OK: the request worked.
(.venv) chris@farm-pc:~/milk-tank$ python fetch.py https://portalTraceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 470, in _make_request self._validate_conn(conn) File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1125, in _validate_conn conn.connect() File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 878, in connect wrapped_socket, is_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 1080, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrap_socket( ^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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 "/home/chris/milk-tank/.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 "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/truststore/_api.py", line 134, in wrap_socket ssl_sock = self._ctx.wrap_socket( ^^^^^^^^^^^^^^^^^^^^^^ 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 "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/truststore/_api.py", line 109, in do_handshake ret = super().do_handshake(block) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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: Hostname mismatch, certificate is not valid for 'portal'. (_ssl.c:1000) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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: Hostname mismatch, certificate is not valid for 'portal'. (_ssl.c:1000) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 696, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.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='portal', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'portal'. (_ssl.c:1000)"))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/chris/milk-tank/fetch.py", line 9, in <module> r = requests.get(url, timeout=10, verify=check) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 87, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/api.py", line 71, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 651, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/sessions.py", line 784, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/milk-tank/.venv/lib/python3.12/site-packages/requests/adapters.py", line 727, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='portal', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'portal'. (_ssl.c:1000)")))
(.venv) chris@farm-pc:~/milk-tank$ python fetch.py https://portal.coop.lan200 OK
So read the words after the colon first. Each reason points somewhere else: the list on your side, the server's certificate, or the name you typed.

verify=False turns the check off
Plenty of answers online say: turn verification off. Chris's fetch script has a no-verify switch, which passes verify=False to requests. With it, the expired server answers 200 OK, plus a warning that checking is strongly advised. But with the check off, Python would accept any server that answered, including someone in between, reading the farm's data. The error was the check doing its job.
(.venv) chris@farm-pc:~/milk-tank$ python fetch.py https://tank.coop.lan --no-verify/home/chris/milk-tank/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py:1129: InsecureRequestWarning: Unverified HTTPS request is being made to host 'tank.coop.lan'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings warnings.warn( 200 OK
Python from python.org on a Mac
On a Mac with Python from python.org, every HTTPS request can fail with these same words, because that Python brings no list of its own at first. The installer leaves a file called Install Certificates.command. Double-click it once, and it installs certifi for that Python.

Recap
So, when Python says certificate verify failed, read the words after the colon first. If it's your own CA, use truststore or point to the CA file. If it's an office proxy, add its CA to the system's list. If it's expired or the wrong name, fix the server or the URL.

If the milk readings are flowing again, a like helps YouTube show this to more beginners, and subscribing brings more fixes like this one, each tested on a real machine.
Every command and every error in this video came from a real Ubuntu PC, and the lab files are linked in the description. Thanks for watching Cloud Explainers.
Sources
- Requests documentation, CA Certificates and SSL Cert Verification (REQUESTS_CA_BUNDLE)
- pip documentation, HTTPS Certificates (--cert, PIP_CERT, system certificates since 24.2)
- truststore documentation (inject_into_ssl, Python 3.10+)
- Ubuntu manual, update-ca-certificates
- Python documentation, Using Python on macOS (Install Certificates.command)
- urllib3 documentation, TLS warnings (InsecureRequestWarning)
Demos: four containers on our own Mac standing in for a farm PC, a co-op's server, an office proxy and a laptop; the farm, the co-op and their certificates are made up. Every command, error and number was real. Watch the full video on YouTube.