在Python环境中访问HTTPS网站时,包括HTTPS需要使用代理的过程中,如果遇到类似SSL: CERTIFICATE_VERIFY_FAILED相关的错误,说明目标网站的HTTPS证书认证不通过,需要忽略对HTTPS证书的验证,可以在访问之前加上
import ssl
try: _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification ssl._create_default_https_context = _create_unverified_https_context
使Python忽略对证书的验证