Python3 import ssl报错解决方法
Posted 風£飛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3 import ssl报错解决方法相关的知识,希望对你有一定的参考价值。
# requests支持https访问必须升级openssl为libressl
# 安装libressl依赖:
yum -y install libffi-devel
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install wget
# 编译安装libressl-2.8.0
下载libressl-2.8.0.tar.gz
https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.8.0.tar.gz
tar xf libressl-2.8.0.tar.gz
cd libressl-2.8.0
./config --prefix=/usr/local/libressl && make && make install
rm -rf libressl-2.8.0 libressl-2.8.0.tar.gz
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -sf /usr/local/libressl/bin/openssl /usr/bin/openssl
ln -sf /usr/local/libressl/include/openssl /usr/include/openssl
ln -sf /usr/local/libressl/lib/libssl.so.45 /usr/lib/
ln -sf /usr/local/libressl/lib/libcrypto.so.43 /usr/lib/
echo \'/usr/local/libressl/lib\' >/etc/ld.so.conf.d/libressl-2.8.0.conf
ldconfig -v #重新加载库文件
进入解压后的目录libressl-2.8.0
./config --prefix=/usr/local/libressl
make && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -sf /usr/local/libressl/bin/openssl /usr/bin/openssl
ln -sf /usr/local/libressl/include/openssl /usr/include/openssl
ln -sf /usr/local/libressl/lib/libssl.so.45 /usr/lib/
ln -sf /usr/local/libressl/lib/libcrypto.so.43 /usr/lib/
新建文件
vim /etc/ld.so.conf.d/libressl-2.8.0.conf
#将以下行加入文件,并保存
/usr/local/libressl/lib
重新加载库文件
ldconfig -v
重新编译python(requests不需要重新编译, ssl需要)先修改python源码的Module/Setup。需要将默认注释掉的关于ssl的5行取消,大约在53%处。
# CSV file helper #_csv _csv.c # Socket module helper for socket(2) _socket socketmodule.c # Socket module helper for SSL support; you must comment out the other # socket line above, and possibly edit the SSL variable: SSL=/usr/local/libressl _ssl _ssl.c \\ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \\ -L$(SSL)/lib -lssl -lcrypto
参考链接:
https://www.cnblogs.com/mengzhilva/p/11059329.html
https://blog.csdn.net/yw804909465/article/details/106426261/
https://www.dazhuanlan.com/2019/12/23/5e003e2e9ac89/
https://blog.csdn.net/Scorpio921/article/details/82682757
以上是关于Python3 import ssl报错解决方法的主要内容,如果未能解决你的问题,请参考以下文章
python3中https urlopen()报错的解决方法
centos6.8安装python3.7.3报错Can't connect to HTTPS URL because the SSL module is not available问题解决
解决pyhton aiohttp ssl:None [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)(代
Centos安装python3导入ssl时解决 ModuleNotFoundError: No module named ‘_ssl‘问题