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

Mac系统使用pip install时SSL证书验证失败问题求助

Fixing SSL Handshake Error When Installing fake-useragent via Pip

Hey there, let's tackle this SSL handshake issue you're hitting with fake-useragent—I've run into similar problems before, so I know how frustrating it can be when basic pip installs go sideways. That tlsv1 alert protocol version error is telling us your system is trying to connect using an outdated TLS protocol (like TLS 1.0/1.1) that the target server no longer supports. Most modern PyPI mirrors and data sources for fake-useragent now require TLS 1.2 or newer.

Here are the step-by-step fixes, ordered by how sustainable they are:

1. Upgrade Pip to the Latest Version

Old versions of pip default to using outdated TLS protocols. Upgrading pip should fix this for most cases:

  • Run this command in your terminal:
    python -m pip install --upgrade pip
    
  • If you still get SSL errors during the pip upgrade, bypass the SSL check temporarily (only for this step) with:
    python -m pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org
    

2. Upgrade Your Python Version

If you're using Python 2.7, 3.4, or older, these versions come with SSL libraries that don't support TLS 1.2+. This is the root cause for many users facing this issue.

  • Install a stable, supported Python version (3.7 or newer) — this will resolve the problem long-term and prevent similar compatibility issues with other packages.

3. Temporarily Bypass SSL Verification (Emergency Fix)

Only use this if you need a quick fix and can't upgrade pip/Python right now (note: this has security risks, so don't make it a habit):

  • Install fake-useragent with trusted hosts specified:
    pip install fake-useragent --trusted-host pypi.org --trusted-host files.pythonhosted.org
    
  • Alternatively, disable SSL verification for the session by setting an environment variable first:
    • On Linux/macOS:
      export PYTHONHTTPSVERIFY=0
      pip install fake-useragent
      
    • On Windows (Command Prompt):
      set PYTHONHTTPSVERIFY=0
      pip install fake-useragent
      

4. Fix fake-useragent's Data Fetching SSL Issue

Sometimes the error isn't from pip itself, but from fake-useragent trying to pull user-agent data from an external site after installation. To work around this:

  • Manually obtain the useragents.json file (the official one used by the package) and save it to your local machine.
  • Set an environment variable pointing to this file before installing:
    • On Linux/macOS:
      export FAKE_USERAGENT_JSON=/path/to/your/useragents.json
      pip install fake-useragent
      
    • On Windows:
      set FAKE_USERAGENT_JSON=C:\path\to\your\useragents.json
      pip install fake-useragent
      

Pick the fix that makes the most sense for your setup—upgrading Python/pip is always the best long-term solution to avoid similar issues down the line.

内容的提问来源于stack exchange,提问作者christopher de jesus

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:57:56