SSLError ssl.c510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

python 采用post方式模拟登录的时候,却报了如下错误:

requests.exceptions.SSLError: HTTPSConnectionPool(host='login.sec.xxx.net', port=436): Max retries exceeded with url: /sec/login (Caused by SSLError(SSLError(1, '_ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed'),))

具体错误如下:

[hdpaa@data ~/workdir/simth/project/olap]$ /home/hdp-aazhe/softwares/python27/bin/python2.7 query_util.py 
/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/urllib3/util/ssl_.py:339: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  SNIMissingWarning
/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/urllib3/util/ssl_.py:137: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecurePlatformWarning
Traceback (most recent call last):
  File "query_util.py", line 187, in <module>
    return_result = obj_get_olap_indices.query_data(in_query_str=query_str)
  File "query_util.py", line 131, in query_data
    redirect_url = self._single_login()
  File "query_util.py", line 71, in _single_login
    r = requests.post(url=query_url, json=True, data=user_passwd, timeout=10)
  File "/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='login.sec.xxx.net', port=436): Max retries exceeded with url: /sec/login (Caused by SSLError(SSLError(1, '_ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed'),))

  • 原因是curl的证书太老了,或者与python版本不匹配,所以需要下载合适版本的证书

解决办法:

sudo pip uninstall -y certifi
sudo pip install certifi==2015.04.28(如果设置了不合适的时间,会提示可以使用的时间,这个必须要设置)

具体操作:

[hdpaa@data ~/workdir/simth/softwares/python27/bin]$ pwd
/home/hdp-aazhe/softwares/python27/bin
[hdpaa@data ~/workdir/simth/softwares/python27/bin]$ ll
total 6168
-rwxrwxr-x 1 hdpaa hdpaa     118 Apr  1  2019 2to3
-rwxrwxr-x 1 hdpaa hdpaa     271 Apr  1  2019 chardetect
-rwxrwxr-x 1 hdpaa hdpaa     259 Apr  1  2019 crypto
-rwxrwxr-x 1 hdpaa hdpaa     267 Apr  1  2019 decrypto
-rwxr-xr-x 1 hdpaa hdpaa     309 Apr  1  2019 easy_install
-rwxr-xr-x 1 hdpaa hdpaa     317 Apr  1  2019 easy_install-2.7
-rwxrwxr-x 1 hdpaa hdpaa     780 Apr  1  2019 f2py
-rwxrwxr-x 1 hdpaa hdpaa     116 Apr  1  2019 idle
-rwxr-xr-x 1 hdpaa hdpaa     322 Apr  1  2019 kafka-tools
-rwxrwxr-x 1 hdpaa hdpaa     258 Apr  1  2019 naked
-rwxr-xr-x 1 hdpaa hdpaa     279 Apr  1  2019 nosetests
-rwxr-xr-x 1 hdpaa hdpaa     287 Apr  1  2019 nosetests-2.7
-rwxrwxr-x 1 hdpaa hdpaa     268 Apr  4  2019 pip
-rwxrwxr-x 1 hdpaa hdpaa     268 Apr  4  2019 pip2
-rwxrwxr-x 1 hdpaa hdpaa     268 Apr  4  2019 pip2.7
-rwxrwxr-x 1 hdpaa hdpaa     101 Apr  1  2019 pydoc
-rwxr-xr-x 1 hdpaa hdpaa 6221535 Apr  1  2019 python2.7
-rwxr-xr-x 1 hdpaa hdpaa    1691 Apr  1  2019 python2.7-config
-rwxrwxr-x 1 hdpaa hdpaa   18564 Apr  1  2019 smtpd.py
-rwxr-xr-x 1 hdpaa hdpaa     319 Apr  1  2019 tabulate
[hdpaa@data ~/workdir/simth/softwares/python27/bin]$ ./pip install certifi==2015.04.28
Collecting certifi==2015.04.28
/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/pip/_vendor/urllib3/util/ssl_.py:369: SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  SNIMissingWarning
/home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/pip/_vendor/urllib3/util/ssl_.py:160: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/86/35/9758a67004a266047c779ae40a3d937869bfc6fc3422f6c606b8afbc9d23/certifi-2015.04.28-py2.py3-none-any.whl (373kB)
    100% |████████████████████████████████| 378kB 10kB/s 
requests 2.18.4 has requirement certifi>=2017.4.17, but you'll have certifi 2015.4.28 which is incompatible.
Installing collected packages: certifi
  Found existing installation: certifi 2019.9.11
    Uninstalling certifi-2019.9.11:
      Successfully uninstalled certifi-2019.9.11
Successfully installed certifi-2015.4.28
You are using pip version 18.0, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

  • 关于pip版本的查看和更换pip版本
  • pip list 查看pip安装的包的版本

  • pip -V 查看pip本身的版本

[hdpaa@data ~/workdir/simth/softwares/python27/bin]$ ./pip -V
pip 18.0 from /home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages/pip (python 2.7)
[hdpaa@data ~/workdir/simth/softwares/python27/bin]$ ./pip show certifi
Name: certifi
Version: 2015.4.28
Summary: Python package for providing Mozilla's CA Bundle.
Home-page: http://certifi.io/
Author: Kenneth Reitz
Author-email: me@kennethreitz.com
License: ISC
Location:  /home/hdp-aazhe/softwares/python27/lib/python2.7/site-packages
Requires: 
Required-by: requests
You are using pip version 18.0, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

参考: https://blog.csdn.net/qq_36260310/article/details/78831054                                     https://blog.csdn.net/wang2008start/article/details/76607321

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值