在Python環(huán)境中訪問HTTPS網(wǎng)站時(shí),包括HTTPS需要使用代理的過程中,如果遇到類似SSL: CERTIFICATE_VERIFY_FAILED相關(guān)的錯(cuò)誤,說明目標(biāo)網(wǎng)站的HTTPS證書認(rèn)證不通過,需要忽略對HTTPS證書的驗(yàn)證,可以在訪問之前加上
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忽略對證書的驗(yàn)證