urllib 中的异常处理

import urllib.request
import urllib.parse
import urllib.error

#异常错误捕获

url = 'https://www.ahvndkmvl.net'

try:
response = urllib.request.urlopen(url)
print(response)
except urllib.error.HTTPError as e:
print(e)
print(e.code)
except urllib.error.URLError as e:
print(e)

posted @ 2018-06-04 10:16  莫问丶过往  阅读(221)  评论(0编辑  收藏  举报