报错情况
在用requests 和 pip 时,由于调用了urlib3 这个包,其有可能warning,提示这不是一个安全的连接,建议检验ssl证书, 执行pip3 install xxx 之后,提示如下:
/usr/share/python-wheels/urllib3-1.24.1-py2.py3-none-any.whl/urllib3/connectionpool.py:849: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
解决方案
It's a bug in old versions of Python that only occurs when Python's ssl module is compiled with OpenSSL 1.1.1. The problem is fixed in recent versions:
- Python 2.7 and 3.5 are not affected because they don't support PHA
- Python 3.6 is affected and cannot be fixed, because 3.6 in security bug-only mode.
- Python 3.7.4 is fixed. 3.7.3 and earlier are affected.
- 3.8-beta is fine.
升级python版本
查看当前python3 版本
python3 --version
安装编译必须包
sudo apt-get install wget build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
下载离线安装包[3.7.9 为例]
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
解压缩并编译安装
tar xzf Python-3.7.9.tgz
cd Python-3.7.9
mkdir /usr/local/python3.7
sudo ./configure --prefix=/usr/local/python3.7 --enable-optimizations
sudo make
#如果不想替换原有python版本
sudo make altinstall
#还是不直接用make install 的好
检查版本
python3.7 -V
如果替换原有版本,重启则生效。