# [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate in Python: how to fix it

> ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate means Python could not build a chain from the server's certificate to a root it trusts. In requests, httpx, aiohttp and urllib the usual causes are a missing or outdated CA bundle, a python.org install on macOS that never ran Install Certificates.command, a corporate proxy that re-signs HTTPS, or a server that does not send its intermediate certificate. Fix the trust store; do not turn verification off.

Source: https://livops.dev/en/guides/error-python-ssl-certificate-verify-failed

By Livops team, the people who build and run Livops. Updated 1 December 2026.

The error as Python prints it, and the same failure as each library wraps it (shortened; the `_ssl.c` line number varies by Python version):

```text
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)
```

| Library | What you see |
| --- | --- |
| requests | `requests.exceptions.SSLError: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: /v1/items (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')))`[6][7] |
| httpx | `httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)`[8] |
| aiohttp | `aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host api.example.com:443 ssl:default [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')]`[10] |
| urllib | `urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)>`[20] |

This page explains what Python is checking, the five causes and how to tell them apart, the fix for each in requests, httpx, aiohttp and urllib, why `verify=False` is not one of them, and where the error shows on Livops.

## What does the error mean?

`SSLCertVerificationError` is the subclass of `SSLError` raised when certificate validation fails[1], and `SSLError` is itself an `OSError`[1]. CPython builds the message from three parts: the library and reason in brackets, `[SSL: CERTIFICATE_VERIFY_FAILED]`, then `certificate verify failed`, then OpenSSL's own reason for the failure[2]. The exception keeps that reason in `verify_message` and its number in `verify_code`[1].

**Read the part after the last colon.** It is OpenSSL's verify error[2][4], and it points to the cause:

| The end of the message | What OpenSSL found | Likely cause |
| --- | --- | --- |
| `unable to get local issuer certificate` | The issuer of a certificate the server sent could not be found[3] | Cause 1, 2, 3 or 4 below |
| `self-signed certificate in certificate chain` | A chain was built, but no trust anchor for it is in your trust store[3] | Cause 3, or a private CA |
| `self-signed certificate` | The server's certificate is self-signed and not in your trust list[3] | The server's setup |
| `certificate has expired` | The certificate's `notAfter` date is before the current time[3] | Cause 5, or a really expired certificate |
| `certificate is not yet valid` (current OpenSSL source adds `or the system clock is incorrect`) | The `notBefore` date is after the current time[3][4] | Cause 5 |
| `Hostname mismatch, certificate is not valid for '...'` | The certificate is for another name[2] | A wrong host name in the URL |

The rest of the page is about the first row, the one people search for.

### Where each library gets its trusted certificates

The fix depends on where your library looks:

- **requests** uses the root certificates from the `certifi` package[5]. `verify` takes a path to a CA bundle file or directory, and the `REQUESTS_CA_BUNDLE` environment variable does the same for every request, with `CURL_CA_BUNDLE` as the fallback[5].
- **httpx** uses the certifi bundle by default[8], and respects the `SSL_CERT_FILE` and `SSL_CERT_DIR` environment variables by default[8]. A custom bundle is passed as an SSL context: `verify=ssl.create_default_context(cafile=...)`[8].
- **aiohttp** uses strict checks for HTTPS by default[9], and its docs note that Python by default uses the system CA certificates[9]. A custom context goes in the `ssl` argument, per request or on `TCPConnector`[9].
- **urllib** goes through `http.client`, which performs certificate and hostname checks by default since Python 3.4.3[12]. Its default context is `ssl.create_default_context()`[13][14], which loads the default CA certificates[1]. A custom one is passed as `urlopen(url, context=...)`; the old `cafile` and `capath` arguments were removed in Python 3.13[11].

"The system CA certificates" means the file and directory OpenSSL was built to use. Python's docs warn that there is no easy way to know whether loading them worked: no error is returned if no certificates are found[1]. The `SSL_CERT_FILE` and `SSL_CERT_DIR` environment variables point OpenSSL at another file or directory[18].

## Find out which cause it is

Three commands, run on the machine where the error happens. Replace `api.example.com` with the host from the error.

```sh
# Where Python's OpenSSL looks, and which environment variables it reads
python -c "import ssl; print(ssl.get_default_verify_paths())"

# Where certifi's bundle is (requests and httpx use it)
python -m certifi

# What the server actually sends
openssl s_client -connect api.example.com:443 -servername api.example.com -showcerts </dev/null
```

`get_default_verify_paths()` returns OpenSSL's default `cafile` and `capath`, each `None` if it does not exist, plus the names of the environment variables that override them[1]. A `cafile` and `capath` that are both `None` mean the default context has nothing to trust. `python -m certifi` prints the path of certifi's bundle[15].

`-showcerts` displays the certificate list exactly as the server sent it, in the server's order; it is not a verified chain[19]. `s_client` prints verification errors and carries on regardless, as it is a test tool[19]. Add `-CAfile "$(python -m certifi)"` to verify against the same roots requests uses; certificates loaded with `-CAfile` are used as trust anchors[19]. Then look at the list:

- **Only one certificate**, issued by an intermediate CA: the server does not send its chain. Cause 4.
- **The top issuer is your company, a firewall or an antivirus product** instead of a public CA: something on the network re-signs HTTPS. Cause 3.
- **A normal public chain** that `s_client` verifies with certifi: your Python's trust store is the problem. Cause 1 or 2.

## Causes, most common first

### 1. A python.org install on macOS that never ran Install Certificates.command

Python's macOS docs tell you to finish the installation by double-clicking **Install Certificates.command** in the `/Applications/Python 3.x/` folder (named after your version). It opens a Terminal window that uses the new Python to download and install SSL root certificates for its use[16]. It is done when the window shows `Successfully installed certifi` and `update complete`[16]. The install is shared by that version's builds, so it only needs to run once[16].

**Fix:** run it. If the error appears right after installing Python on a Mac and the same code works elsewhere, this is the cause.

### 2. The CA bundle is missing or out of date

requests stopped shipping its own roots and takes them from certifi, so users can update the trusted certificates without changing the requests version[5]. certifi provides Mozilla's curated collection of root certificates[15]; an old certifi in a frozen environment or a pinned `requirements.txt` lacks the roots added since. requests says it plainly: for the sake of security, upgrade certifi frequently[5].

**Fix:**

```sh
python -m pip install --upgrade certifi
```

and keep `certifi` in `requirements.txt` without an old exact pin. For aiohttp and urllib, which use the system certificates, check the `get_default_verify_paths()` output above: if both paths are `None`, either install the operating system's CA certificates or give the library certifi's bundle, as aiohttp's docs show[9]:

```python
import ssl, certifi, aiohttp

ctx = ssl.create_default_context(cafile=certifi.where())
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=ctx)) as session:
    async with session.get("https://api.example.com/v1/items") as resp:
        data = await resp.json()
```

### 3. A corporate proxy or antivirus re-signs HTTPS

On an office network, or with an antivirus that inspects HTTPS, the certificate your code receives was issued by the proxy's own root, not by a public CA. Your browser trusts it because IT installed that root on the computer; certifi does not have it. requests' docs: using a proxy for HTTPS connections typically requires your machine to trust the proxy's root certificate[5]. Proxy settings can come from the environment without any code: requests reads `http_proxy`, `https_proxy`, `no_proxy` and `all_proxy`[5], and urllib installs a proxy handler when a `*_proxy` variable is set[11].

**Fix A: trust the company root explicitly.** Get the root certificate in PEM format from IT. certifi does not support adding or removing certificates[15], so do not edit its file; make your own bundle. A `cafile` is a file of concatenated CA certificates in PEM format[1]:

```sh
cat "$(python -m certifi)" company-root.pem > ca-bundle.pem
```

Then point each library at it:

```python
import ssl, urllib.request
import requests, httpx

CA = "/path/to/ca-bundle.pem"

requests.get("https://api.example.com", verify=CA)                      # requests
httpx.get("https://api.example.com", verify=ssl.create_default_context(cafile=CA))  # httpx
ctx = ssl.create_default_context(cafile=CA)                             # aiohttp: TCPConnector(ssl=ctx)
urllib.request.urlopen("https://api.example.com", context=ctx)          # urllib
```

Or without code changes: `REQUESTS_CA_BUNDLE=/path/to/ca-bundle.pem` for requests[5], `SSL_CERT_FILE=/path/to/ca-bundle.pem` for httpx[8] and for OpenSSL's defaults, which urllib and aiohttp use[1][18].

**Fix B: use the system trust store.** truststore exposes the operating system's trust store (the Security framework on macOS, CryptoAPI on Windows, OpenSSL on Linux) as an `ssl.SSLContext`; it needs Python 3.10 or later[17]. Call it once, as early as possible, in your application, not in a library[17]:

```python
import truststore
truststore.inject_into_ssl()   # before requests, aiohttp or urllib3 create connections
```

It works for requests directly[17]. For httpx, pass `verify=truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)`[8].

### 4. The server does not send its intermediate certificate

A server should send its own certificate plus the intermediates that link it to a root. If it sends only its own, OpenSSL cannot find the issuer and the error is exactly `unable to get local issuer certificate`[3]. Tools that use the operating system's trust store can hide this: truststore's docs note that system trust stores can fetch missing intermediate certificates[17], while certifi is a fixed collection of root certificates[15]. So the site can open on your computer and fail in Python. The `-showcerts` check above shows it: one certificate where there should be two or more.

**Fix:** if the server is yours, configure it to send the full chain, its certificate followed by the intermediates, and check again with `s_client`. If it is someone else's API, tell them; meanwhile truststore (Fix B above) lets the operating system fill the gap[17].

### 5. The clock is wrong

A certificate is valid between its `notBefore` and `notAfter` dates[1]. OpenSSL compares them with the current time[3], so a machine whose clock is years behind or ahead rejects good certificates: the message then ends in `certificate is not yet valid` or `certificate has expired` instead[3][4].

**Fix:** check the time in UTC and sync the clock:

```sh
date -u
```

The dates in a certificate are in GMT[1], so a server's time zone does not matter, only the real time.

## Why not verify=False?

Every library has a switch that makes the error go away: `verify=False` in requests and httpx[5][8], `ssl=False` in aiohttp[9], `ssl._create_unverified_context()` for `http.client` and urllib[12]. They all remove the check the error comes from.

requests' docs spell out the cost: with `verify=False`, requests accepts any TLS certificate the server presents and ignores hostname mismatches and expired certificates, which makes the application vulnerable to man-in-the-middle attacks[5]. Python's `ssl` docs say the same of `CERT_NONE`: on the client side, just about any certificate is accepted[1], and they recommend `create_default_context()` for client use, which enables certificate validation and hostname checking[1].

requests calls `verify=False` useful during local development or testing[5]: fine for one command that tells you whether certificates are the problem at all, never in code that ships: a bot or an API client that sends tokens over an unverified connection cannot tell whether it is talking to the real server.

## On Livops

- **Where it shows.** An outgoing HTTPS call that fails raises in your code. If it happens while the app starts, the deploy fails as `start_failed` and the **Logs** page shows the app's last words: a web app's previous version keeps running, a bot's previous version was stopped first, so the bot is down until a deploy succeeds. If it happens later, in a handler, the traceback is on the **Logs** page; `livops logs <service> -f` follows it from the terminal ([CLI](https://livops.dev/en/docs/cli)). See [The app did not start](https://livops.dev/en/docs/error-start).
- **Dependencies come from requirements.txt.** Put `certifi`, and `truststore` if you use it, in `requirements.txt`. Livops runs Python 3.10 to 3.14, all of which truststore supports. Put the version in `.python-version` at the project root; see [Frameworks and livops.json](https://livops.dev/en/docs/frameworks).
- **CA settings as variables.** `REQUESTS_CA_BUNDLE` and `SSL_CERT_FILE` are ordinary environment variables: set them in **Settings → Variables**. Variables are passed to a service when it starts, so new values take effect on the next deploy, or at once if you restart the service. See [Variables](https://livops.dev/en/docs/variables). If the API you call uses a private CA, commit its root certificate with the code (a CA certificate is public, not a secret) and build the path from your own file, for example `Path(__file__).with_name("company-root.pem")`.
- **The clock.** The container's clock runs on UTC ([Cron and workers](https://livops.dev/en/docs/cron-workers)), which is the right time for certificate checks; certificate dates are in GMT.

A timeout on the way to `api.telegram.org` is a different error: see [telegram.error.TimedOut](https://livops.dev/en/guides/error-telegram-timed-out). If the app stops on `No module named 'certifi'` or `'truststore'`, see [ModuleNotFoundError](https://livops.dev/en/guides/error-module-not-found-python).

## Questions

**What does unable to get local issuer certificate mean?**

OpenSSL, which Python uses for TLS, could not find the certificate that issued one of the certificates the server sent. Either your trust store does not have the root the chain leads to, as with an old CA bundle or a company proxy's own root, or the server did not send the intermediate certificate that links its certificate to a public root.

**Is verify=False an acceptable fix?**

No. The requests documentation says that with verify set to False any TLS certificate is accepted, hostname mismatches and expired certificates are ignored, and the application becomes vulnerable to man-in-the-middle attacks. Use it only for a moment during local testing, never in code that runs in production.

**Why does it fail only on my Mac?**

If you installed Python from python.org, its installer asks you to run Install Certificates.command in the Python folder under Applications. It installs certifi and the root certificates that build of Python uses. Until you run it once, HTTPS calls can fail with this error.

**Why does the site open in my browser but fail in Python?**

Usually one of two things. The server may not send its intermediate certificate: the operating system's trust store can fetch a missing intermediate, while requests and httpx use the certifi bundle, a fixed collection of root certificates. Or your network re-signs HTTPS with a company root that IT installed on your computer but that certifi does not contain.

**How do I use my company's root certificate with requests?**

Make a bundle file that contains certifi's certificates followed by your company's root certificate in PEM format, and point the REQUESTS_CA_BUNDLE environment variable or the verify argument at that file. Do not edit certifi's own file: certifi does not support adding or removing certificates. Or install truststore and call truststore.inject_into_ssl() so Python uses the system trust store.

**Does upgrading certifi help?**

When the bundle is old, yes: requests takes its root certificates from certifi and recommends upgrading it frequently, and httpx uses certifi by default. It does not help when the chain ends in a private or company root, when the server's chain is incomplete, or when the system clock is wrong.

**The message says certificate has expired or is not yet valid. Is that the same problem?**

It is the same exception with a different reason. OpenSSL compares the certificate's notBefore and notAfter dates with the current time, so either the server's certificate really expired or the clock on the machine making the request is wrong. Check the time with date -u before anything else.

## Sources

1. [Python Docs — ssl (TLS/SSL wrapper for socket objects)](https://docs.python.org/3/library/ssl.html). Checked 1 December 2026.
2. [CPython source — Modules/_ssl.c](https://github.com/python/cpython/blob/main/Modules/_ssl.c). Checked 1 December 2026.
3. [OpenSSL Docs source — X509_STORE_CTX_get_error](https://github.com/openssl/openssl/blob/master/doc/man3/X509_STORE_CTX_get_error.pod). Checked 1 December 2026.
4. [OpenSSL source — crypto/x509/x509_txt.c](https://github.com/openssl/openssl/blob/master/crypto/x509/x509_txt.c). Checked 1 December 2026.
5. [Requests — Advanced Usage (SSL Cert Verification, CA Certificates, Proxies)](https://requests.readthedocs.io/en/latest/user/advanced/). Checked 1 December 2026.
6. [Requests source — src/requests/adapters.py](https://github.com/psf/requests/blob/main/src/requests/adapters.py). Checked 1 December 2026.
7. [urllib3 source — src/urllib3/exceptions.py](https://github.com/urllib3/urllib3/blob/main/src/urllib3/exceptions.py). Checked 1 December 2026.
8. [HTTPX — SSL](https://www.python-httpx.org/advanced/ssl/). Checked 1 December 2026.
9. [aiohttp — Advanced Client Usage](https://docs.aiohttp.org/en/stable/client_advanced.html). Checked 1 December 2026.
10. [aiohttp source — aiohttp/client_exceptions.py](https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client_exceptions.py). Checked 1 December 2026.
11. [Python Docs — urllib.request](https://docs.python.org/3/library/urllib.request.html). Checked 1 December 2026.
12. [Python Docs — http.client](https://docs.python.org/3/library/http.client.html). Checked 1 December 2026.
13. [CPython source — Lib/ssl.py](https://github.com/python/cpython/blob/main/Lib/ssl.py). Checked 1 December 2026.
14. [CPython source — Lib/http/client.py](https://github.com/python/cpython/blob/main/Lib/http/client.py). Checked 1 December 2026.
15. [certifi — PyPI](https://pypi.org/project/certifi/). Checked 1 December 2026.
16. [Python Docs — Using Python on macOS](https://docs.python.org/3/using/mac.html). Checked 1 December 2026.
17. [truststore documentation](https://truststore.readthedocs.io/en/latest/). Checked 1 December 2026.
18. [OpenSSL Docs — openssl-env](https://docs.openssl.org/master/man7/openssl-env/). Checked 1 December 2026.
19. [OpenSSL Docs source — openssl-s_client](https://github.com/openssl/openssl/blob/master/doc/man1/openssl-s_client.pod.in). Checked 1 December 2026.
20. [CPython source — Lib/urllib/error.py](https://github.com/python/cpython/blob/main/Lib/urllib/error.py). Checked 1 December 2026.
