已解决 - import ssl的问题(_ssl)

问题描述

python里使用requests调用api时报错:

  1. Max retries exceeded with url(事后证明与此无关)

  1. 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等等)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值