ssl.SSLCertVerificationError is raised when Python's SSL layer cannot verify the server's TLS certificate. This can mean the certificate is expired, self-signed, issued by an untrusted authority, or the hostname does not match the certificate.
Why it happens
- •The server's SSL certificate has expired.
- •A self-signed certificate is used without adding it to the trusted store.
- •The system's CA bundle is outdated or missing (common on macOS after Python install).
- •A corporate proxy performs SSL inspection and presents its own certificate.
Examples
Code that triggers the error
import urllib.request
urllib.request.urlopen("https://expired.badssl.com/")Error output
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007)
How to fix it
On macOS, run the 'Install Certificates.command' script in your Python installation directory. Update your CA bundle with certifi. If you control the server, renew the expired certificate. Never disable SSL verification in production code.
Fixed code
import requests
# Production: keep verification enabled
response = requests.get("https://api.example.com", timeout=10)
# Development only: disable verification (never in production)
# response = requests.get("https://...", verify=False)Related errors
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free