[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

2017-09-21

python2.7.14或3.6.2配置nagios发送微信报错:[SSL: CERTIFICATE_VERIFY_FAILED]

访问https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=id&corpsecret=secrect
发现证书用的是qy.weixin.qq.com,可能是域名和证书不匹配导致的问题。

1、版本python2.7.12升级Python-2.7.14.tgz
https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
tar zxf Python-2.7.14.tgz
cd Python-2.7.14
./configure --prefix=/usr/local/python2.7
make
make install

2、import ssl取消ssl验证
def main():
ssl._create_default_https_context = ssl._create_unverified_context
token=get_token()
3、python编译问题
Python build finished, but the necessary bits to build these modules were not found:
_tkinter bsddb185 dl
imageop sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
源码目录下的 setup.py 中有关 hashlib 与 ssl 依赖性检测

Failed to build these modules:
_hashlib _ssl

4、pip uninstall -y certifi solved the issue.
turned out the Python package "certifi" which is part of a other Python package "Tornado" was causing this error.
python package Requests 2.16.0 started requiring Certifi

pip install requests==2.15.1;
pip3.6 install requests
Collecting requests
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests)
Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
100% |████████████████████████████████| 133kB 113kB/s
Collecting idna<2.7,>=2.5 (from requests)
Using cached idna-2.6-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
Downloading certifi-2017.7.27.1-py2.py3-none-any.whl (349kB)
100% |████████████████████████████████| 358kB 44kB/s
Installing collected packages: urllib3, idna, chardet, certifi, requests
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22

pip3.6 uninstall -y certifi
Uninstalling certifi-2017.7.27.1:
Successfully uninstalled certifi-2017.7.27.1

分类:Linux | 标签: |

相关日志

评论被关闭!