_潜行者

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

错误1:AttributeError: 'module' object has no attribute '_create_unverified_context',

错误2:URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)>

 1 import ssl
 2 
 3 try:
 4     _create_unverified_https_context = ssl._create_unverified_context
 5 except AttributeError:
 6     # Legacy Python that doesn't verify HTTPS certificates by default
 7     pass
 8 else:
 9     # Handle target environment that doesn't support HTTPS verification
10     ssl._create_default_https_context = _create_unverified_https_context

官方解释:

This guidance is aimed primarily at system administrators that wish to adopt newer 
versions of Python that implement this PEP in legacy environments that do not yet
support certificate verification on HTTPS connections. For example, an administrator
may opt out by adding the monkeypatch above to sitecustomize.py in their Standard
Operating Environment for Python. Applications and libraries SHOULD NOT be making
this change process wide (except perhaps in response to a system administrator
controlled configuration setting). Particularly security sensitive applications should always provide an explicit
application defined SSL context rather than relying on the default behaviour
of the underlying Python implementation.

 

posted on 2018-05-23 11:33  _潜行者  阅读(984)  评论(0编辑  收藏  举报