python3.7.8 Can‘t connect to HTTPS URL because the SSL

由于openssl 1.0.1存在安全问题,python3自3.7版本后要求依赖openssl 1.0.2以上或libressl;

python3.7以上建议使用libressl代替openssl,需要通过源码编译安装libressl

下载源码包

wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.0.2.tar.gz

解压

tar -zxvf libressl-3.0.2.tar.gz

配置安装路径

mkdir /usr/local/libressl
cd libressl-3.0.2
./configure --prefix=/usr/local/libressl

安装

make -j8 & sudo make install

创建软连接代替openssl

mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl
ln -s /usr/local/libressl/include/openssl /usr/include/openssl
echo /usr/local/libressl/lib >> /etc/ld.so.conf.d/libressl-3.0.2.conf
ldconfig -v

验证是否安装完成

openssl version
export LDFLAGS="-L/usr/local/libressl/lib"
export CPPFLAGS="-I/usr/local/libressl/include"
export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"

配置编译安装python

下载并配置安装python 可根据自己的版本进行安装  建议3.7.8
wget https://www.python.org/ftp/python/3.7.8/Python-3.7.8.tgz --no-check-certificate
tar -zxvf Python-3.7.8.tgz 
cd Python-3.7.8/
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto
make
make install

删除原有的软连接
rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3
新建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3 
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 
python3 
import ssl

···
安装libressl

根据错误提示,发现需要安装libressl,所以需要重现下载和安装libressl 来替代openssl

(1)下载地址:https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.4.tar.gz

tar zxvf libressl-2.7.4.tar.gz -C ./

cd cd libressl-2.7.4

./config --prefix=/usr/local

sudo make install
(2)新建或修改 /etc/ld.so.conf.d/local.conf 配置文件,添加如下内容:

/usr/local/lib
然后将 /usr/local/lib 目录加入到模块加载目录。
重新加载共享模块:

sudo ldconfig -v
重新编译Python3.8
回到 Python3.8目录,编辑安装文件 Modules/Setup
删除有关 ssl 编译代码的注释,共 4 行

SSL=/usr/local
_ssl _ssl.c
-DUSE_SSL -I ( S S L ) / i n c l u d e − I (SSL)/include -I (SSL)/includeI(SSL)/include/openssl
-L$(SSL)/lib -lssl -lcrypto
这样重新编译python之后,就可以正常导入ssl模块了
···

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值