######刚学Python 这是对着案例敲得以下代码, 执行的时候就报错了
from urllib.request import build_opener,ProxyHandler
from urllib.error import URLError
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
url = 'http://www.baidu.com'
proxy_handler = ProxyHandler({
'http':'http://127.0.0.1:8080',
'https':'https://127.0.0.1:8080'
})
opener = build_opener(proxy_handler)
try:
result = opener.open(url)
html = result.read().decode('utf-8')
print(html)
except URLError as e:
print(e.reason)