python3 urllib.requesturlopen 一個https 時ssl證書錯誤!

不知道從那個版本起,python用urlopen打開一個https時會驗證一次 SSL 證書,當目標使用的是自簽名的證書時就會爆出一個python

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>url

解決辦法是:經過導入ssl模塊,把證書驗證關了ssl

import ssl
ssl._create_default_https_context = ssl._create_unverified_contextimport

相關文章
相關標籤/搜索