python -- NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+

报错分析

  • 完整的报错:urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
  • 报错分析:LibreSSL 是 OpenSSL 的一个分支,LibreSSL 2.8.3 与OpenSSL 1.1.1版本相似(有差异)。Mac版python里的ssl默认使用LibreSSL 2.8.3 编译,也就是OpenSSL 1.1.1。而urllib3 v2仅支持OpenSSL 1.1.1以上的版本,因此MAC版python里的ssl版本落后了。

解决办法:

  1. 升级LibreSSL(没用,LibreSSL升级了但是python里的ssl库没更新)
# 查看当前用户,确保非root(id 不为0)
whoami
# 查看是否是root
id -u

# 修改目录权限
sudo chown -R $(whoami) /opt/homebrew

# 升级libressl
brew update
brew upgrade libressl

# 设置libressl环境变量
echo 'export PATH="/opt/homebrew/opt/libressl/bin:$PATH"' >> ~/.zshrc
# 设置编译器环境变量:为了让编译器找到 LibreSSL
echo 'export LDFLAGS="-L$(brew --prefix openssl)/lib"' >> ~/.zshrc 
echo 'export CPPFLAGS="-I$(brew --prefix openssl)/include"' >> ~/.zshrc

# 使生效
source ~/.zshrc

# 查看版本
openssl version
>LibreSSL 3.9.1
  1. urllib3降级(可行,但有种越混越回去的感觉)
pip install 'urllib3<2.0'
  1. 虚拟环境单独安装对应版本的urllib3 和 OpenSSL

  2. 重新源码编译python

./configure --with-openssl=$(brew --prefix openssl)
# ./configure --with-openssl=$(brew --prefix libressl)

make
sudo make install
  1. 忽略警告
import warnings
from urllib3.exceptions import NotOpenSSLWarning
warnings.filterwarnings("ignore", category=NotOpenSSLWarning)

相关推荐

  1. Vue中v-for和v-if优先级(23

    2024-04-03 05:24:03       26 阅读
  2. SteamVR学习(三)V1.2.3

    2024-04-03 05:24:03       61 阅读
  3. SGP.22-V.3.1-安全2

    2024-04-03 05:24:03       37 阅读
  4. 3.11笔记2

    2024-04-03 05:24:03       31 阅读
  5. nacos v2.2.3 docker简单安装使用

    2024-04-03 05:24:03       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-03 05:24:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-03 05:24:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-03 05:24:03       87 阅读
  4. Python语言-面向对象

    2024-04-03 05:24:03       96 阅读

热门阅读

  1. 关于其他服务器篡改请求头导致登录失效

    2024-04-03 05:24:03       38 阅读
  2. 大语言模型开发各个阶段的评估方法(未完)

    2024-04-03 05:24:03       33 阅读
  3. 后管配置js

    2024-04-03 05:24:03       39 阅读
  4. 【Python】文件内容编码类型检测

    2024-04-03 05:24:03       35 阅读
  5. Android Drawable - Shape Drawable使用详解

    2024-04-03 05:24:03       37 阅读
  6. 定时推送任务 Apache HttpClient/okhttp3

    2024-04-03 05:24:03       31 阅读
  7. P1002 过河卒:图论动态规划入门

    2024-04-03 05:24:03       39 阅读