SSLCertVerificationError: What It Means and How to Fix It
Error reference
SSLCertVerificationError
Language
Severity
HighWhen it happens
ssl.SSLCertVerificationError is raised when Python's SSL layer cannot verify the server's TLS certificate.
Potential fixes
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.
Related errors
Deep dive
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.
Potential fixes
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.
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)
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)Practice in English
How would you explain a SSLCertVerificationError to a fellow dev? Choose the right phrase:
"I hit an error...
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