Skip to content

Python ssl.SSLCertVerificationError

Key idea:

Python requests/urllib3 fails with ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] unable to get local issuer certificate. Python takes its CA bundle from the certifi package. Fix: pip install --upgrade certifi. On macOS — run /Applications/Python 3.x/Install Certificates.command. Corporate proxy with MITM — export REQUESTS_CA_BUNDLE=/path/to/corporate-ca.pem.

Below: details, example, related, FAQ.

Check your site's SSL →

Details

  • requests uses certifi.where() for the default bundle
  • SSL_CERT_FILE env var — override for stdlib ssl
  • REQUESTS_CA_BUNDLE — specifically for requests
  • macOS Python installer doesn't set up CAs automatically — run Install Certificates.command
  • verify=False disables the check (debug only!)

Example

# Update certifi
$ pip install --upgrade certifi

# macOS fix
$ /Applications/Python\ 3.12/Install\ Certificates.command

# Corporate MITM proxy — add CA
$ export REQUESTS_CA_BUNDLE=/etc/ssl/certs/corporate-mitm.pem

# Python code: explicit bundle
import requests, certifi
resp = requests.get('https://api.example.com', verify=certifi.where())

# Debug only (NEVER in prod):
resp = requests.get('https://api.example.com', verify=False)

Related

TL;DR: Understanding SSL Error: Python ssl.SSLCertVerificationError: CERTIFICATE_VERIFY_FAILED

The ssl.SSLCertVerificationError: CERTIFICATE_VERIFY_FAILED error in Python indicates that the SSL certificate presented by a server is not trusted. This typically occurs due to expired certificates, self-signed certificates, or missing root certificates in the certificate chain. To resolve this, ensure the server's SSL certificate is valid and trusted, and update your local certificate store if necessary.

Common Causes of CERTIFICATE_VERIFY_FAILED

When encountering the ssl.SSLCertVerificationError: CERTIFICATE_VERIFY_FAILED error, it's essential to understand the various factors that can trigger this issue. Here are the most common causes:

  • Expired Certificates: SSL certificates have a specific validity period. If the certificate has expired, clients will reject the connection.
  • Self-Signed Certificates: While self-signed certificates can be used for development, they are not trusted by default in production environments. This can lead to verification failures.
  • Missing Intermediate Certificates: If the server does not provide the complete certificate chain, clients may fail to verify the server's identity, resulting in an error.
  • Outdated Certificate Authorities (CAs): If your local certificate store does not have the latest CA certificates, it may not trust the SSL certificate presented by the server.
  • Hostname Mismatch: The domain name in the SSL certificate must match the domain being accessed. A mismatch can cause verification to fail.

Understanding these causes is crucial for troubleshooting and resolving the CERTIFICATE_VERIFY_FAILED error effectively.

Resolving ssl.SSLCertVerificationError: Practical Steps

To resolve the ssl.SSLCertVerificationError: CERTIFICATE_VERIFY_FAILED error, you can take several practical steps. Here’s a structured approach to troubleshooting:

  1. Check the SSL Certificate Expiry: Use the following command to check the SSL certificate's expiration date:
openssl s_client -connect example.com:443 -servername example.com

Replace example.com with the domain you are trying to access. Look for the notAfter field to see the expiration date.

  1. Verify the Certificate Chain: Ensure that the server provides the complete certificate chain. You can check this with:
openssl s_client -connect example.com:443 -showcerts

This command will display the entire certificate chain. Ensure that all certificates are valid and properly linked.

  1. Update Your Local CA Certificates: If the error persists, your local CA certificates might be outdated. On Debian-based systems, you can update them with:
sudo apt-get update && sudo apt-get install --reinstall ca-certificates

For Red Hat-based systems, use:

sudo yum update ca-certificates
  1. Use a Trusted Certificate: If you are using a self-signed certificate for development purposes, consider switching to a trusted certificate authority for production. Services like Let's Encrypt provide free SSL certificates that are widely trusted.
  1. Bypass SSL Verification (Not Recommended): If you need a temporary workaround, you can disable SSL verification in Python. However, this is not recommended for production environments:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

This will bypass SSL verification but expose your application to security risks.

By following these steps, you can systematically identify and resolve the ssl.SSLCertVerificationError: CERTIFICATE_VERIFY_FAILED error, ensuring secure connections to your servers.

CertificateExpiry, issuer, domains (SAN)
ChainIntermediate and root CA validation
TLS ProtocolTLS version and cipher suite
VulnerabilitiesHeartbleed, POODLE, weak ciphers

Why teams trust us

TLS 1.3
supported
Full
CA chain check
<2s
result
30/14/7
days-to-expiry alerts

How it works

1

Enter domain

2

TLS chain verified

3

Expiry date & vulnerabilities

What Does the SSL Check Cover?

SSL/TLS is the encryption protocol that protects data between the browser and server. Our tool analyzes the certificate, chain of trust, TLS version, and knownvulnerabilities.

Certificate Details

Issuer, validity period, signature algorithm, covered domains (SAN), and validation type (DV/OV/EV).

Chain of Trust

Full chain verification: from leaf certificate through intermediates to root CA.

TLS Analysis

Protocol version (TLS 1.2/1.3), cipher suites, Perfect Forward Secrecy (PFS) support.

Expiry Alerts

Set up a monitor — get Telegram and email alerts 30/14/7 days before expiration.

DV vs OV vs EV Certificates

DV (Domain Validation)
  • Confirms domain ownership only
  • Issued in minutes automatically
  • Free via Let's Encrypt
  • Suitable for most websites
  • Most common certificate type
OV / EV
  • Organization (OV) or Extended Validation (EV)
  • Issued in 1-5 business days
  • Costs $50 to $500/year
  • For finance, e-commerce, government sites
  • Increases user trust

Who uses this

DevOps

SSL certificate monitoring

Security

TLS config audit

SEO

HTTPS as ranking factor

E-commerce

customer trust

Common Mistakes

Expired certificateBrowsers block sites with expired SSL. Set up auto-renewal or monitoring.
Incomplete certificate chainWithout intermediate CA, some browsers and bots cannot verify the certificate.
Mixed content on HTTPS siteHTTP resources on an HTTPS page — the browser lock icon disappears, reducing trust.
Using TLS 1.0/1.1Legacy TLS versions have known vulnerabilities. Use TLS 1.2+ or 1.3.
Domain mismatch in certificateThe certificate must cover all site domains, including www and subdomains.

Best Practices

Set up auto-renewalLet's Encrypt + certbot with cron — certificate renews automatically every 60-90 days.
Enable HSTSStrict-Transport-Security header forces browsers to always use HTTPS.
Use TLS 1.3TLS 1.3 is faster (1-RTT handshake) and safer — legacy ciphers removed.
Monitor expiration datesCreate a monitor on Enterno.io — get notified well before expiration.
Verify chain after renewalAfter certificate renewal, confirm that intermediate certificates are installed.

Get more with a free account

SSL certificate monitoring, check history and alerts 30 days before expiry.

Sign up free

Learn more

Sources

Frequently Asked Questions

macOS fresh install — why?

The Python.org installer ships certifi, but the system trust store is separate. Running Install Certificates.command links the bundle.

Behind corporate VPN?

Export REQUESTS_CA_BUNDLE to the corporate root CA. IT usually provides the file.

Is verify=False OK?

Debug only in dev. In prod = MITM vulnerability. Use httpbin.org with self-signed + a local CA in trust.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.