urllib3 v2 only supports OpenSSL 1.1.1+
# Superset 启动报错:urllib3 v2 only supports OpenSSL 1.1.1+ 解决方案
在基于 Ambari 和 Bigtop 部署 Superset 4.1.2 过程中,如果你运行如下命令:
(superset_venv) [root@centos1 superset-4.1.2]# superset run -p 8080 --with-threads --reload --debugger
1
出现以下 ImportError:
(superset_venv) [root@centos1 superset-4.1.2]# superset run -p 8080 --with-threads --reload --debugger
Traceback (most recent call last):
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/bin/superset", line 5, in <module>
from superset.cli.main import superset
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/superset/__init__.py", line 20, in <module>
from superset.app import create_app # noqa: F401
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/superset/app.py", line 24, in <module>
from superset.initialization import SupersetAppInitializer
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/superset/initialization/__init__.py", line 36, in <module>
from superset.extensions import (
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/superset/extensions/__init__.py", line 38, in <module>
from superset.utils.machine_auth import MachineAuthProviderFactory
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/superset/utils/machine_auth.py", line 26, in <module>
from selenium.webdriver.remote.webdriver import WebDriver
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/selenium/webdriver/__init__.py", line 19, in <module>
from .chrome.webdriver import WebDriver as Chrome # noqa
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 19, in <module>
from selenium.webdriver.chromium.webdriver import ChromiumDriver
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 21, in <module>
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/selenium/webdriver/chromium/remote_connection.py", line 19, in <module>
from selenium.webdriver.remote.remote_connection import RemoteConnection
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/selenium/webdriver/remote/remote_connection.py", line 27, in <module>
import urllib3
File "/opt/modules/bigtop/dl/superset-4.1.2/superset_venv/lib/python3.9/site-packages/urllib3/__init__.py", line 42, in <module>
raise ImportError(
ImportError: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'. See: https://github.com/urllib3/
urllib3/issues/2168
(superset_venv) [root@centos1 superset-4.1.2]# yum install openssl11 openssl11-devel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
这类问题在 CentOS 7.x 等系统自带 OpenSSL 版本较低时尤为常见。
# 问题背景与成因分析
提示
该错误本质上是因为 Python 所用的 ssl 模块被编译到的 OpenSSL 版本过低(1.0.2k),而 urllib3 v2 明确要求 >=1.1.1,否则会拒绝加载。
- CentOS 7.x 自带 OpenSSL 版本为 1.0.2k,许多大数据基础设施同样基于此环境;
- 随着新版本 Python 依赖库(如 requests、urllib3、selenium 等)升级,底层对 OpenSSL 要求提高;
- 你在虚拟环境下
pip install
或升级了相关依赖后,环境中的 urllib3 已经是 v2 版本,强制要求 OpenSSL 1.1.1+; - 若不处理,后续所有涉及 Python https 通信的依赖都会报类似错。
即使你通过 yum 或 apt 升级了 openssl 系统包,如果 Python 不是用新 openssl 重新编译,依旧无法解决根因!
# 典型场景与相关依赖
依赖包 | 影响表现 | 备注 |
---|---|---|
urllib3 | 报错导火索,底层 https 相关 | pip install 升级后常触发 |
requests | 各类第三方 API 调用失败 | 间接依赖 urllib3 |
selenium | Superset 截图、监控、自动化测试等 | 依赖 urllib3 2.x |
pyopenssl | ssl 扩展,依赖底层 openssl 库 | 通常无独立升级无用 |
# 排查与环境检查
# 1. 检查 openssl 版本
openssl version
# 输出如:OpenSSL 1.0.2k-fips 26 Jan 2017
1
2
2
# 2. 检查 Python ssl 库编译依赖
python -c "import ssl; print(ssl.OPENSSL_VERSION)"
# 通常输出仍为 OpenSSL 1.0.2k-fips
1
2
2
笔记
哪怕你系统层面已安装 openssl11 或 openssl3,Python 仍有可能用的是旧库,需要重点关注!
# 解决思路与实操流程
一定要让 Python 的 ssl 模块用到新版本 openssl!否则换多少 pip 包都无效。
# 步骤一:安装新版 openssl
提示
对于 CentOS 7 可直接安装 openssl11 及对应 devel 包:
yum install -y openssl11 openssl11-devel
1
# 步骤二:重新编译/安装 Python,并指定 openssl 路径
- 推荐用 Miniconda/Anaconda,其自带的新 openssl 并隔离依赖冲突,非常适合大数据生态一键部署场景。
- 若二进制安装自定义 Python,务必加参数:
--with-openssl=/usr/local/openssl11
。
注意
已有的虚拟环境无法直接切换底层 openssl,需要新建 conda/env 或重建 venv。
# 步骤三:新建虚拟环境并激活
示例:基于 miniconda 安装 Python 3.9 并新建环境
conda create -n superset_env python=3.9 openssl=1.1.1 -c conda-forge -y
conda activate superset_env
1
2
2
提示
conda 管理的 openssl 路径优先,能彻底隔离系统依赖。
# 步骤四:重新安装 Superset 及全部依赖
提示
必须在新环境下重装全部依赖,不能直接 cp 旧 venv 目录。
pip install apache-superset==4.1.2
# 或根据需求安装 requirements.txt
1
2
2
# 步骤五:再次验证
superset run -p 8080 --with-threads --reload --debugger
# 不再报 urllib3 v2 only supports OpenSSL 1.1.1+ 即为修复完成
1
2
2
# 一键安装脚本
#!/bin/bash
# ----------------------------------------------------------------------------
# 脚本名称:build_openssl_python39_idempotent.sh
# 功能 :在 /opt/modules/virtual_env 下幂等地编译安装 OpenSSL-1.1.1w(GitHub + ghfast.top)
# 和 Python-3.9.19(华为云镜像),确保每次运行不重复执行
# 适用 :CentOS 7/8 以 root 身份运行
# ----------------------------------------------------------------------------
set -euo pipefail
# 未定义变量时退出,pipeline 中任一失败即退出
# ─── 全局变量 ────────────────────────────────────────────────────────────────
BASE_DIR="/opt/modules/virtual_env"
# OpenSSL 配置(走 GitHub + ghfast.top)
OPENSSL_VERSION="1.1.1w"
OPENSSL_TAG="OpenSSL_${OPENSSL_VERSION//./_}" # eg: OpenSSL_1_1_1w
OPENSSL_TAR="${OPENSSL_TAG}.tar.gz"
OPENSSL_URL="https://ghfast.top/github.com/openssl/openssl/archive/refs/tags/${OPENSSL_TAR}"
OPENSSL_SRC_DIR="openssl-${OPENSSL_TAG}"
OPENSSL_PREFIX="${BASE_DIR}/openssl-${OPENSSL_VERSION}"
# Python 配置(走华为云镜像)
PYTHON_VERSION="3.9.19"
PYTHON_TAR="Python-${PYTHON_VERSION}.tgz"
PYTHON_URL="https://repo.huaweicloud.com/python/${PYTHON_VERSION}/${PYTHON_TAR}"
PYTHON_SRC_DIR="Python-${PYTHON_VERSION}"
PYTHON_PREFIX="${BASE_DIR}/python-${PYTHON_VERSION}"
# ─── 安装系统依赖 ───────────────────────────────────────────────────────────
yum groupinstall -y "Development Tools"
yum install -y \
zlib-devel bzip2-devel ncurses-devel sqlite-devel \
readline-devel tk-devel gdbm-devel libdb-devel \
libpcap-devel xz-devel curl libffi-devel
# ─── 1. 编译安装 OpenSSL ─────────────────────────────────────────────────────
mkdir -p "$BASE_DIR"
cd "$BASE_DIR"
if [[ ! -x "${OPENSSL_PREFIX}/bin/openssl" ]]; then
echo "→ 安装 OpenSSL ${OPENSSL_VERSION} ..."
# 下载
if [[ ! -f "$OPENSSL_TAR" ]]; then
curl -fSL "$OPENSSL_URL" -o "$OPENSSL_TAR"
fi
# 解压
if [[ ! -d "$OPENSSL_SRC_DIR" ]]; then
tar xzf "$OPENSSL_TAR"
fi
# 编译
cd "$OPENSSL_SRC_DIR"
./config --prefix="$OPENSSL_PREFIX" shared zlib
make -j"$(nproc)"
make install_sw
echo "✔ OpenSSL 已安装到 $OPENSSL_PREFIX"
else
echo "✔ OpenSSL 已存在,跳过编译:${OPENSSL_PREFIX}"
fi
# ─── 2. 编译安装 Python ─────────────────────────────────────────────────────
cd "$BASE_DIR"
if [[ ! -x "${PYTHON_PREFIX}/bin/python3.9" ]]; then
echo "→ 安装 Python ${PYTHON_VERSION} ..."
# 下载
if [[ ! -f "$PYTHON_TAR" ]]; then
curl -fSL "$PYTHON_URL" -o "$PYTHON_TAR"
fi
# 解压
if [[ ! -d "$PYTHON_SRC_DIR" ]]; then
tar xzf "$PYTHON_TAR"
fi
# 编译
cd "$PYTHON_SRC_DIR"
export CPPFLAGS="-I${OPENSSL_PREFIX}/include"
export LDFLAGS="-L${OPENSSL_PREFIX}/lib"
export LD_LIBRARY_PATH="${OPENSSL_PREFIX}/lib:${LD_LIBRARY_PATH:-}"
export PKG_CONFIG_PATH="${OPENSSL_PREFIX}/lib/pkgconfig"
./configure --prefix="$PYTHON_PREFIX" \
--with-openssl="$OPENSSL_PREFIX"
make -j"$(nproc)"
make install
echo "✔ Python 已安装到 $PYTHON_PREFIX"
else
echo "✔ Python 已存在,跳过编译:${PYTHON_PREFIX}"
fi
# ─── 3. 安装 pip 并设国内镜像 ─────────────────────────────────────────────────
if ! "${PYTHON_PREFIX}/bin/python3.9" -m pip --version &>/dev/null; then
echo "→ 安装 pip ..."
"${PYTHON_PREFIX}/bin/python3.9" -m ensurepip
"${PYTHON_PREFIX}/bin/python3.9" -m pip install --upgrade pip \
-i https://mirrors.aliyun.com/pypi/simple
echo "✔ pip 安装完毕"
else
echo "✔ pip 已存在,跳过安装"
fi
# ─── 4. 验证安装结果 ───────────────────────────────────────────────────────────
echo
echo "=== 安装验证 ==="
"${PYTHON_PREFIX}/bin/python3.9" --version
"${PYTHON_PREFIX}/bin/python3.9" -c "import ssl; print('OpenSSL version:', ssl.OPENSSL_VERSION)"
"${PYTHON_PREFIX}/bin/pip3.9" --version
echo
echo "私有 OpenSSL 目录:$OPENSSL_PREFIX"
echo "私有 Python 目录:$PYTHON_PREFIX"
# ─── 5. 建立 /usr/local/bin 下的软连接 ────────────────────────────────────────
ln -sf "${PYTHON_PREFIX}/bin/python3.9" /usr/local/bin/python3.9
ln -sf "${PYTHON_PREFIX}/bin/pip3.9" /usr/local/bin/pip3.9
echo "✔ 已在 /usr/local/bin 下创建 python3.9 和 pip3.9 软链接"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116