问题描述
python里使用requests调用api时报错:
Max retries exceeded with url(事后证明与此无关)
Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")
找到根源:定位到SSL
由于我的python版本是3.11,比较新,所为国内网站搜出来的办法都不管用
[root@xsource ~]# python
Python 3.11.1
>>> import ssl
报错说找不到 _ssl
还得去外网
I traced it down and found out that the ssl module got built successfully ; however, the problem was that the Python Setup.py script excluded installation of the _ssl module because it did not pass an import test. Part of the issue is that python setup.py script relied on the environment variable OPENSSL_LDFLAGS, which was not defined if openssl was installed in the default system config.
I fixed this issue by applying this patch.
解决办法
--- configure.old 2022-10-25 14:13:13.616179815 -0400
+++ configure 2022-10-25 14:12:11.828979774 -0400
fi
if test x"$PKG_CONFIG" != x""; then
- OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
+ OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L --keep-system-libs 2>/dev/null`
其实就是找到python安装包的configure文件,给相应命令添加一个参数,再重新编译python即可
tar xvzf Python-3.11.1.tgz
cd Python-3.11.1
./configure --enable-optimizations && make altinstall
后续
如果对已经部署好的3.11进行重新编译,完成后,就不需要做别的了(不需要重新软链接、安装pip、uwsgi等等)