You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elementary OS下Python Requests设verify=False仍遇SSLError求助

Fixing Requests SSLError on Elementary OS (Even With 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):

  1. Refresh System Root Certificates
    Elementary OS relies on the system’s CA certificate store, and if it’s outdated or corrupted, even verify=False might 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-certificates
    

    This ensures your system has the latest trusted root certificates, which Requests uses by default.

  2. 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.crt
    

    In PyCharm, you can add this environment variable in your run configuration under "Environment Variables".

  3. Upgrade Requests and urllib3
    Outdated versions of Requests or its underlying urllib3 library often have SSL-related bugs. Upgrade them using pip (add --user if you don’t want to modify system packages):

    pip3 install --upgrade requests urllib3
    # Or for user-level installation:
    pip3 install --user --upgrade requests urllib3
    

    Make sure you’re using the pip that corresponds to your /usr/local/bin/python3 (check with which pip3).

  4. 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_PROXY
    

    If 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:39:17