• Python执行SSL握手报错 AttributeError: 'module' object has no attribute 'X509_up_ref'处理


    执行requests报错

    ====> Sending Panels to webhook https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0b8a94fd-5421-4dfa-bbf8-xxxxxxxxxxxx....
    From cffi callback <function _verify_callback at 0x10f3e3758>:
    Traceback (most recent call last):
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL/SSL.py", line 309, in wrapper
        _lib.X509_up_ref(x509)
    AttributeError: 'module' object has no attribute 'X509_up_ref'
    Traceback (most recent call last):
      File "gpr_multi_panels.py", line 184, in <module>
        send_multi_panels(job_json_file_full_path)
      File "gpr_multi_panels.py", line 173, in send_multi_panels
        json=new_post_data)
      File "/Library/Python/2.7/site-packages/requests/api.py", line 110, in post
        return request('post', url, data=data, json=json, **kwargs)
      File "/Library/Python/2.7/site-packages/requests/api.py", line 56, in request
        return session.request(method=method, url=url, **kwargs)
      File "/Library/Python/2.7/site-packages/requests/sessions.py", line 488, in request
        resp = self.send(prep, **send_kwargs)
      File "/Library/Python/2.7/site-packages/requests/sessions.py", line 609, in send
        r = adapter.send(request, **kwargs)
      File "/Library/Python/2.7/site-packages/requests/adapters.py", line 497, in send
        raise SSLError(e, request=request)
    requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)
    stephendeMacBook-Pro:GrafanaPanelReporter stephen$ 
    

    解决问题

    网络查询提示原因为cryptography库版本过低,升级之。

    # 升级pip
    stephendeMacBook-Pro:GrafanaPanelReporter stephen$ pip install --upgrade pip
    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
    Collecting pip
      Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
         |████████████████████████████████| 1.4MB 269kB/s 
    Installing collected packages: pip
      Found existing installation: pip 19.3.1
        Uninstalling pip-19.3.1:
          Successfully uninstalled pip-19.3.1
    Successfully installed pip-20.0.2
    stephendeMacBook-Pro:GrafanaPanelReporter stephen$ 
    
    # 升级cryptography
    stephendeMacBook-Pro:GrafanaPanelReporter stephen$ sudo pip install -U cryptography
    Password:
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
    WARNING: The directory '/Users/stephen/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
    Collecting cryptography
      Downloading cryptography-2.8-cp27-cp27m-macosx_10_6_intel.whl (1.6 MB)
         |████████████████████████████████| 1.6 MB 478 kB/s 
    Requirement already satisfied, skipping upgrade: ipaddress; python_version < "3" in /Library/Python/2.7/site-packages (from cryptography) (1.0.17)
    Requirement already satisfied, skipping upgrade: enum34; python_version < "3" in /Library/Python/2.7/site-packages (from cryptography) (1.1.6)
    Requirement already satisfied, skipping upgrade: six>=1.4.1 in /usr/local/lib/python2.7/site-packages (from cryptography) (1.11.0)
    Requirement already satisfied, skipping upgrade: cffi!=1.11.3,>=1.8 in /Library/Python/2.7/site-packages (from cryptography) (1.8.3)
    Requirement already satisfied, skipping upgrade: pycparser in /Library/Python/2.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography) (2.17)
    Installing collected packages: cryptography
      Attempting uninstall: cryptography
        Found existing installation: cryptography 1.5.3
        Uninstalling cryptography-1.5.3:
          Successfully uninstalled cryptography-1.5.3
    Successfully installed cryptography-2.8
    stephendeMacBook-Pro:GrafanaPanelReporter stephen$ 
    

    重新测试OK

    stephendeMacBook-Pro:GrafanaPanelReporter stephen$ 
    ====> Sending Panels to webhook https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0b8a94fd-5421-4dfa-bbf8-xxxxxxxxxxxx....
    {"errcode":0,"errmsg":"ok"}
    stephendeMacBook-Pro:GrafanaPanelReporter stephen$ 
    
  • 相关阅读:
    省选知识点
    寒假练习
    水题欢乐赛-套路
    2019年12月(2)
    洛谷P1347 排序
    Aizu
    2019年12月(1)
    【CSP2019】
    联系博主
    UVA1420 Priest John's Busiest Day【贪心】
  • 原文地址:https://www.cnblogs.com/thatsit/p/python-zhi-xingssl-wo-shou-bao-cuo-attributeerror-.html
Copyright © 2020-2023  润新知