The error “SSL: CERTIFICATE_VERIFY_FAILED” indicates that Python is unable to verify the SSL certificate for the Google Cloud Storage or BigQuery endpoint. This is typically caused by a problem with your local SSL setup or missing CA certificates.
Here’s how to troubleshoot and fix this issue:
1. Verify Python Environment SSL Certificates
Ensure your Python environment has access to valid CA certificates.
• Anaconda Users: Run the following command to update certificates:
conda install -c anaconda certifi
• Non-Anaconda Users: If you’re using the standard Python installation, update the certifi package:
pip install --upgrade certifi
2. Set SSL Certificates Path (If Necessary)
Sometimes Python doesn’t locate the certificates correctly. Set the REQUESTS_CA_BUNDLE or SSL_CERT_FILE environment variable to the location of your certificates:
• Locate your certifi certificates:
import certifi
print(certifi.where())
This will print the path to the CA certificates file.
• Set the environment variable:
export REQUESTS_CA_BUNDLE=/path/to/your/certifi/cacert.pem
For Windows, you can set this variable in PowerShell:
$env:REQUESTS_CA_BUNDLE = "C:\path\to\certifi\cacert.pem"
3. Update Google Cloud Libraries
Make sure you are using the latest version of google-cloud-storage and google-cloud-bigquery libraries, as they often include fixes for SSL issues:
pip install --upgrade google-cloud-storage google-cloud-bigquery
4. Test Internet Access for SSL Verification
Run this test to confirm if your SSL verification works:
import requests
response = requests.get("https://www.google.com")
print(response.status_code)
If this fails, it confirms a broader SSL issue on your system.
5. Disable SSL Verification (Temporary Solution)
This is not recommended for production but can be used to bypass SSL verification for testing:
• Using the google-cloud-storage library:
from google.cloud import storage
from google.auth.transport.requests import Request
client = storage.Client(client_options={"api_endpoint": "https://storage.googleapis.com"})
session = Request()
session.verify = False
• Globally Disable SSL Verification: (Not recommended)
export PYTHONHTTPSVERIFY=0
6. Check Local Network Restrictions
If the issue persists, ensure that your local network or firewall is not blocking Google’s SSL certificates. You may need to:
• Use a different network or VPN.
• Check if the corporate firewall is intercepting HTTPS traffic and provide the proper certificates.
7. Alternative Debugging Steps
• Run on a Different Machine/Environment: Try executing the script on a different machine to rule out environment-specific issues.
• Reinstall Python or Anaconda: If the issue remains unresolved, consider reinstalling Python or your Anaconda environment to refresh SSL configurations.
Let me know if further assistance is required!