環境: Mac 10.13.6 python3.7html
代碼python
from urllib.request import urlopen html = urlopen('https://en.wikipedia.org/wiki/Kevin_Bacon',)
報錯以下urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) , 大概意思是證書(certificate)驗證失敗url
解決辦法:code
from urllib.request import urlopen import ssl # 導入頭文件 # 生成證書上下文(unverified 就是不驗證https證書) context = ssl._create_unverified_context() # 改成以下便可 html = urlopen('https://en.wikipedia.org/wiki/Kevin_Bacon', context=context)
from urllib.request import urlopen import ssl ssl._create_default_https_context = ssl._create_unverified_context html = urlopen('https://en.wikipedia.org/wiki/Kevin_Bacon',)
這裏是requests請求https證書報錯解決辦法: http://www.javashuo.com/article/p-fimuzvmy-ec.htmlhtm