centos7中python3.6报错ModuleNotFoundError: No module named '_ssl' 或者 Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))

时间:2021-11-26 02:16:18

如果在运行爬虫时报此错:requests.exceptions.SSLError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))并且在python命令行中引用import ssl ,报错ModuleNotFoundError: No module named '_ssl'采用以下方法:

解决方法:
步骤:
1、安装依赖:yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel

2、修改python配置文件,并重新编译安装:
(1)vi Setup.dist

centos7中python3.6报错ModuleNotFoundError: No module named '_ssl'  或者 Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))

修改内容:如下图红线内内容全部将“#”去掉,谨记

centos7中python3.6报错ModuleNotFoundError: No module named '_ssl'  或者 Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))

(2)重新编译安装Python3

centos7中python3.6报错ModuleNotFoundError: No module named '_ssl'  或者 Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))

然后:

make ## 编译
make install 安装

3、测试:此时import ssl不报错

centos7中python3.6报错ModuleNotFoundError: No module named '_ssl'  或者 Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))

原文链接:https://blog.csdn.net/qq_23889009/article/details/100887640