You write a simple script to fetch an API, scrape web data with BeautifulSoup, or install packages with pip, and execution crashes immediately with an OpenSSL exception: urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)> or requests.exceptions.SSLError: HTTPSConnectionPool: Max retries exceeded with url (Caused by SSLError(SSLCertVerificationError)). Your network connection is active and the destination website opens fine in your web browser, yet Python refuses to connect.
The SSL certificate verify failed in Python error occurs when Python's internal SSL/TLS implementation cannot validate the target server's public certificate against a trusted Certificate Authority (CA) root store. Unlike web browsers that maintain continuously synchronized commercial root certificate databases, Python relies on environment-specific trust stores that often lack updated root bundles or break behind corporate security proxies.
While disabling SSL verification with verify=False is frequently suggested on online forums, doing so strips all encryption security and leaves your application vulnerable to man-in-the-middle attacks. In this comprehensive technical guide, we explain why Python fails to verify SSL certificates across macOS, Windows, Linux, and enterprise proxy environments, providing permanent, production-grade solutions. If your team requires scalable backend integration or API automation, discover our specialized software engineering and API development services.
1. Why Python Fails to Verify SSL Certificates

When your Python program initiates an HTTPS handshake, the destination web server presents its SSL certificate chain (server certificate, intermediate CA, and root CA). Python's ssl module checks this chain against trusted anchors. Verification fails when one of four common bottlenecks occurs:
- Missing Default Certificates on macOS: Official Python installers downloaded from Python.org for macOS do not use the native Apple Keychain trust store. Instead, they bundle a private copy of OpenSSL that has no root certificates installed by default.
- Outdated Certifi Root Bundle: Libraries like
requestsandurllib3rely on the Mozilla CA certificate bundle distributed by the Certifi package. If Certifi is outdated, newly rotated intermediate certificates cannot be verified. - Corporate Firewalls and Intercepting Proxies: Enterprise networks (Zscaler, Palo Alto Networks, Fortinet) perform SSL inspection by re-signing traffic with internal corporate certificates. If Python does not know your company's custom root CA, verification aborts instantly.
- System Clock Drift: SSL certificates are strictly bounded by valid date ranges. If your machine's system clock drifts significantly into the past or future, valid certificates are rejected as expired.
Security Warning: Avoid verify=False in Production
Setting verify=False in requests or creating an unverified SSL context with ssl._create_unverified_context() stops all TLS certificate validation. Any attacker on your local network or public Wi-Fi can intercept passwords, tokens, and private data.
2. Step-by-Step Fixes for macOS, Windows, and Linux
Apply these targeted fixes based on your operating system and environment:
Fix 1: Run the macOS Install Certificates Command
If you are on a Mac and installed Python from Python.org, a certificate installation script is included in your Python application folder. Running this command links the Certifi bundle directly to Python's OpenSSL environment:
# For Python 3.12 (adjust version number to match your installation)
/Applications/Python\ 3.12/Install\ Certificates.command
# Or run dynamically via your active Python interpreter
python3 -c "import ssl, certifi; print(certifi.where())"Once the script executes, it installs updated CA certificates into /Library/Frameworks/Python.framework/Versions/.../etc/openssl/certs, resolving the unable to get local issuer certificate error permanently.
Fix 2: Upgrade the Certifi and Requests Packages
Ensure your Python environment is running the latest Mozilla root bundle by upgrading Certifi, urllib3, and requests:
# Upgrade certificate packages in your virtualenv or global environment
pip install --upgrade certifi requests urllib3Fix 3: Explicitly Pass the CA Bundle in Python Requests
According to the official Requests documentation, you can point requests directly to Certifi's validated certificate bundle:
import requests
import certifi
# Pass certifi bundle explicitly to guarantee valid root validation
response = requests.get('https://api.example.com/data', verify=certifi.where())
print(response.status_code)3. Resolving SSL Errors Behind Corporate Proxies and VPNs
In enterprise corporate environments where firewalls inspect HTTPS traffic, Python does not automatically trust self-signed company root certificates. You must instruct Python and pip to trust your organization's custom root CA file:
# Set environment variables for requests and OpenSSL (Linux / macOS)
export REQUESTS_CA_BUNDLE=/path/to/corporate-ca.crt
export SSL_CERT_FILE=/path/to/corporate-ca.crt
# Windows PowerShell
$env:REQUESTS_CA_BUNDLE = "C:\certs\corporate-ca.crt"
$env:SSL_CERT_FILE = "C:\certs\corporate-ca.crt"Fixing Pip SSL Certificate Failures
If running pip install itself fails with SSL verification errors behind a corporate proxy, configure pip to use your trusted corporate bundle:
# Tell pip to use your organization custom CA bundle
pip config set global.cert /path/to/corporate-ca.crt4. Diagnostic Matrix: Common SSL Error Scenarios
| Error Message | Root Cause | Operating System | Recommended Solution |
|---|---|---|---|
| unable to get local issuer certificate | Missing OpenSSL CA roots | macOS | Run Install Certificates.command |
| certificate verify failed: self signed certificate | Corporate proxy / firewall inspection | Windows / Linux | Set REQUESTS_CA_BUNDLE to company CRT |
| certificate has expired | Outdated Certifi or system clock drift | All Platforms | Sync OS time; run pip install -U certifi |
| hostname doesn't match | Server certificate issued for different domain | All Platforms | Verify target URL and server SAN configuration |
For more architectural guides on API integration and network protocols, read our technical breakdown on resolving CORS origin errors in modern applications or check our tutorial on setting up CI/CD with GitHub Actions. For custom backend security audits, connect with our team through our contact page.
5. Where to Go From Here
Fixing Python SSL certificate verification properly protects your data pipelines and user credentials from interception. As you build and deploy production Python services, incorporate these reliable security practices:
- Never commit
verify=Falseto version control; use environment variables to supply trusted CA certificates in staging and production. - Keep the
certifidependency regularly updated in yourrequirements.txtorpyproject.tomllockfiles. - In Docker containers, ensure your base image installs the system certificate bundle (
apt-get install -y ca-certificatesorapk add --no-cache ca-certificates) before installing Python dependencies.