在Python環(huán)境中訪問HTTPS網(wǎng)站時,包括HTTPS需要使用代理的過程中,如果遇到類似SSL: CERTIFICATE_VERIFY_FAILED相關(guān)的錯誤,說明目標網(wǎng)站的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忽略對證書的驗證