Elementary OS下Python Requests设verify=False仍遇SSLError求助
verify=False) Hey there! Let’s work through this SSL error you’re facing with Python Requests on Elementary OS—frustrating that even skipping verification with verify=False isn’t resolving it, right? I’ve dealt with similar quirks on Debian-based distros like Elementary, so here are actionable steps to get things working:
First, let’s recap your setup to make sure we’re on the same page:
You’re running this code in
/usr/local/bin/python3(a non-system Python install?) and hitting an error when requesting GitHub’s API:import requests page = requests.get('https://api.github.com/events')Partial error traceback:
/usr/local/bin/python3 /home/led/PycharmProjects/urllib_p/urllib_p.py Traceback (most recent call last): File "/usr/lib/python3/dist-packages/requests/adapters.py", line 376, in send timeout=timeout File "/usr/lib/python3/dist-packages/urllib3/conn...
Let’s Try These Fixes (in order):
Refresh System Root Certificates
Elementary OS relies on the system’s CA certificate store, and if it’s outdated or corrupted, evenverify=Falsemight not bypass the issue (since some low-level SSL checks still reference it). Run these commands in your terminal:sudo apt update && sudo apt install --reinstall ca-certificates sudo update-ca-certificatesThis ensures your system has the latest trusted root certificates, which Requests uses by default.
Point Requests to the System Certificate Bundle
If you’re using a custom Python installation (like/usr/local/bin/python3), it might not be able to find the system’s certificate file automatically. Try explicitly specifying it in your request:import requests page = requests.get('https://api.github.com/events', verify='/etc/ssl/certs/ca-certificates.crt')Alternatively, set an environment variable to make this permanent for your shell/PyCharm session:
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crtIn PyCharm, you can add this environment variable in your run configuration under "Environment Variables".
Upgrade Requests and urllib3
Outdated versions of Requests or its underlying urllib3 library often have SSL-related bugs. Upgrade them using pip (add--userif you don’t want to modify system packages):pip3 install --upgrade requests urllib3 # Or for user-level installation: pip3 install --user --upgrade requests urllib3Make sure you’re using the pip that corresponds to your
/usr/local/bin/python3(check withwhich pip3).Check for Proxy Interference
Sometimes system-wide proxies (even if you didn’t set them explicitly) can mess with SSL verification. Temporarily unset proxy variables and test your script again:unset HTTP_PROXY HTTPS_PROXYIf this fixes the issue, you’ll need to configure Requests to work with your proxy properly (or adjust your system proxy settings).
A quick note: While verify=False works as a temporary workaround, it’s insecure for production use—you’ll want to fix the root certificate issue instead of skipping validation long-term.
内容的提问来源于stack exchange,提问作者Ledorub

