异常代码如下
>>> import urllib.request
>>> import urllib.error
>>> req = urllib.request.Request("http://www.ooxx-baidu.com")
>>> try:
urllib.request.urlopen(req)
except urllib.error.URLError as e:
print(e.reason)
[Errno 11001] getaddrinfo failed
404错误
>>> req = urllib.request.Request("http://www.fishC.com/ooxx.html")
>>> try:
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
print(e.code)
print(e.read())
404
b'<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor="white">\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n'