zoukankan      html  css  js  c++  java
  • python3 openssl问题(贼有用)

    目录

    一、问题描述

    二、排查过程

    三、总结

    四、写在最后

    一、问题描述

    在python3 执行任何的request请求时,都会报以下的错误,纵观全网,以下基本尝试过了,对于我这个是无效的,后来不知道怎么无意中发现我安装Python3.7的时候编译里写的编译参数--with-ssl是错误的,而正确的是--with-openssl=/usr/local/openssl(openssl写自己的路径,有的是/usr/include/openssl)
     
    requests.exceptions.SSLError: HTTPSConnectionPool(host='XXXXXXX', port=443): Max retries exceeded with url: XXXXXXXX (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

    二、排查过程

    1、查看openssl版本是不是比较低

    [root@lemon Python-3.7.3]# openssl version
    OpenSSL 1.1.1g  21 Apr 2020

    如果版本比较低,安装较新版本

    wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
    tar -zxvf openssl-1.1.1g.tar.gz
    cd openssl-1.1.1g/
    ./config --prefix=/usr/local/openssl
    make
    make install

    备份和替换

    mv /usr/bin/openssl /usr/bin/openssl.old
    mv /usr/include/openssl /usr/include/openssl.old
    ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
    ln -s /usr/local/openssl/include/openssl /usr/include/openssl
    echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
    ldconfig 

    2、查看Python3是否有编译openssl

    [root@lemon Python-3.7.3]# python3 -c "import sysconfig; print(sysconfig.get_config_var('CONFIG_ARGS'))"
    '--prefix=/usr/local/python3' '--with-openssl=/usr/local/openssl' '--enable-shared'

    没有的话,重新编译安装Python3

    yum install -y libffi libffi-devel
    cd Python-3.7.3
    ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --enable-shared
    make && make install

    重新连接

    ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
    echo "/usr/local/python3/lib" >/etc/ld.so.conf.d/python3.conf
    ldconfig

    三、总结

    有问题还是要根据日志去排查,而不是根据网上的一通瞎搞,挺浪费时间的。每个人遇到的场景不一样,解决的办法肯定也不一样,但是背后的原因可能是一样的,这就需要内功了,后面再好好研究一下openssl这个鬼东西。

    四、写在最后

    在平凡中坚持前行,总有一天会遇见不一样的自己。
     
    写博客记录、思考、总结,趟过的坑不趟第二遍。
     
    所有的文章,皆同步在公众号“运维汪”,可关注;也可加入“不扯淡,专注于技术”的QQ群:753512236

  • 相关阅读:
    python 学习
    快速排序
    U3D AStar 案例
    U3D AStar 算法原理
    .net core 实时通讯
    .net 算法复杂度
    U3D MVC 背包案例
    U3D 对象池
    Unity网络基础(NetWork)
    U3D Socket实现简易通讯
  • 原文地址:https://www.cnblogs.com/lemon-le/p/13419429.html
Copyright © 2011-2022 走看看