python urllib.request error 处理

from socket import timeout
try:
    response = urllib.request.urlopen(url, timeout=10).read().decode('utf-8')
except (HTTPError, URLError) as error:
    logging.error('Data of %s not retrieved because %s\nURL: %s', name, error, url)
except timeout:
    logging.error('socket timed out - URL %s', url)
else:
    logging.info('Access successful.')
上一篇:【龙珠-Python训练营】Python学习-条件语句、异常处理


下一篇:python学习笔记_第17天(异常和错误)