import socketfrom urllib import request,errortry: ???response = request.urlopen(‘https://cuiqingcai.com/index/htm‘,timeout=0.01)except error.HTTPError as e: ???#先捕获子类错误HTTPError ???print(e.reason,e.code,e.headers,sep=‘\n‘)except error.URLError as e: ???????#再捕获父类错误URLError ???print(type(e.reason)) ?#reason有时返回对象 ???print(e.reason) ???if isinstance(e.reason,socket.timeout): ???????print(‘TIMEOUT‘)else: ???print(‘Request Successfully‘)
urllib.error
原文地址:https://www.cnblogs.com/vector-wyw/p/10416026.html