Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“

这篇具有很好参考价值的文章主要介绍了Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言:

最近在linux系统里安装python3.11之后,使用pip安装第三方库、requests库进行网络请求都会报这个错Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

 查找了网上很多方法,看见了一个大佬的,是在pip 的命令最后面加上:

-i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

加上之后确实可以安装第三方库了,但是在我用requests库进行请求的时候Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

又报了这个错

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

 但是请求http的话,是不会报错的

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

于是在百度里到处找解决办法,最后在一个大佬的文章里Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“) 详解_tobybo的博客-CSDN博客,看见了方法,由于大佬写的不好理解,有些步骤也省略了(我也花了很长时间才理解的),我在这详细记录下解决办法。

解决办法:

安装最新版的OpenSSL:

        进入 /usr/local 目录:

cd /usr/local

(建议跟我一样的目录,后面不用改命令)

        下载最新版的OpenSSL:wget https://www.openssl.org/source/openssl-3.0.2.tar.gz --no-check-certificateCaused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         下载成功后解压:

tar -zxvf openssl-3.0.2.tar.gz

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        解压成功后进入解压后的目录里:

cd openssl-3.0.2/

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         输入命令配置:

./Configure --prefix=/usr/local/openssl

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         出现这个代表配置成功,但是大概率会失败Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        一般会失败报错:Can‘t locate IPC/Cmd.pm in

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        原因是因为缺少IPC/Cmd.pm模块,需要安装这个模块,安装方法在一个大佬文章Linux安装openssl出现Can‘t locate IPC/Cmd.pm in,error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1_无奈的码农的博客-CSDN博客里找到的。

        先安装perl-CPAN: 

yum install -y perl-CPAN

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https
         进入perl shell中:

perl -MCPAN -e shell

         进入后第一步选yes,第二步选manual,第三步选yesCaused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         出现以下cpan[1]>就可以了Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        安装缺少的模块:

install IPC/Cmd.pm

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https
         安装成功

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         按Ctrl+D退出cpan

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         重新输入命令配置:

./Configure --prefix=/usr/local/openssl

         配置成功

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         配置安装:

make && make install

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         安装成功后进入到安装后的目录里:

cd /usr/local/openssl

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        可以看到目录里没有lib目录,只有lib64,我们需要手动复制一个lib目录出来(这一步非常关键):

cp -rf /usr/local/openssl/lib64 /usr/local/openssl/lib

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         至此,OpenSSL安装成功

重新安装python3:

卸载python3(之前没有安装的话,跳过这一步):

        先检查自己是否安装了python3:

python3 --version

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        卸载掉之前安装的python3,直接删除掉自己安装python3的目录就可以了

rm -rf /usr/local/python3

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

安装python3:

        下载安装包:

        一、linux系统里直接下载(速度比较慢,不推荐):

        进入到/usr/local目录下(推荐使用一样的目录)

cd /usr/local

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        输入命令下载:

wget https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tgz

        二、Windows下载好后上传到linux(推荐)                

        下载安装包,python官网:Welcome to Python.org(我下载的是python3.11.2)

        也可以在网盘下载:百度网盘 请输入提取码

        下载好后,上传到linux系统的/usr/local/目录(我是用的宝塔上传的,要安装宝塔的话可以看上一篇:linux安装Jenkins详细步骤_黄花闺女郭德纲的博客-CSDN博客)

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        解压压缩包:

tar -xvf Python-3.11.2.tgz

        下载安装依赖:

sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

        进入解压的python目录里

cd Python-3.11.2/

        配置编译模式(后面的参数非常重要,一定不要省略):

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https
        编译模式配置成功后使用make -j加快编译

make -j

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

        编译完成后,安装:

make install

        安装完成:Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         添加软链接,让python3pip3这两个命令指向刚刚安装的python3.11

ln -s /usr/local/python3/bin/python3.11 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.11 /usr/bin/pip3

         如果这个错Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         需要删除之前建立的软连接

rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         再重新添加软连接Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         检查python3是否安装完毕:

python3 --version

Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         测试一下pip3能不能正常下载第三方库(可以成功下载了):Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

         测试一下requests能不能发起https的请求(可以成功发起请求了):Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https

       至此python3安装成功 

         最后安装第三方库时提示的pip升级,可以复制下面绿色的命令执行,升级pipCaused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“,linux,python,perl,ssl,https文章来源地址https://www.toymoban.com/news/detail-701084.html

到了这里,关于Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包