>>> 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
>>> 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'\r\n404 Not Found \r\n\r\n404 Not Found
\r\n
nginx \r\n\r\n\r\n'