参考了http://bookshadow.com/weblog/2015/04/22/sae-python-weibo-sdk-certificate-verify-failed/
#coding=utf-8 import urllib.request import ssl ssl._create_default_https_context = ssl._create_unverified_context def getHtml(url): page = urllib.request.urlopen(url) html = page.read() return html html = getHtml("https://www.baidu.com") print(html)
1⃣️python3里url模块已发生变化,urllib需改成urllib.request
2⃣️urllib打开一个http链接时会验证一次ssl证书,如果网站使用的是自签名的证书会抛出一个URL_Error,可以直接全局取消证书验证