Linux Centos python3请求https类型网站报错问题解决-报错原因openssl版本过低


问题描述

在linux centos 上运行python脚本出现错误错误

Traceback (most recent call last):
  File "/usr/local/python3/lib/python3.8/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/usr/local/python3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/local/python3/lib/python3.8/site-packages/urllib3/util/retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='xxxxxxxxx', port=443): Max retries exceeded with url: /admin/login.html (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:1108)')))

During handling of the above exception, another exception occurred:

问题解决

首先安装依赖

yum install zlib zlib-devel bzip2-devel openssl-devel ncurses-devel libuuid-devel sqlite-devel readline-devel tcl-devel tk-devel lzma gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

依赖安装

下载openssl源代码
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
下载openssl源码

解压
tar zxf openssl-1.1.1g.tar.gz
解压

配置编译openssl环境
./config –prefix=/usr/local/openssl shared zlib
配置openssl编译环境
make编译
make
make编译
make install安装
make install
创建软链接
ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
openssl version
查看安装的openssl是否成功
安装成功以后下载python源码
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
下载python源码
解压 tar zxf Python-3.8.6.tgz
解压python
重点链接 openssl 设置编译环境
./configure –prefix=/usr/local/python3 –with-openssl=/usr/local/openssl/
编译
make编译
make
make
make install
make install

python3再次测试
测试python3

最终测试测试脚本情况正常运行了
测试问题是否解决

如果上述已经安装了requests 报错说是requests还报错尝试
最好把python加入到环境变量中(如果上述步骤imports requests 找不到那可以试试加入到环境变量)

export PATH=”/usr/local/python3/bin:$PATH”
vim /etc/profile

修改完毕以后source /etc/pfofile一下弄完以后再次尝试看看。如果不行删除在重新编译看看遗漏了哪些细节。测试在linux
CentOS Linux release 7.9.2009 (Core) 3.10.0-1160.102.1.el7.x86_64 #1 SMP Tue Oct 17 15:42:21 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux


文章作者: peiqiF4ck
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 peiqiF4ck !
  目录