4.测试超时异常处理
try: response=urllib.request.urlopen("http://httpbin.org/get",timeout=0.01)#如果0.01秒内数据没有响应就超时 print(response.read().decode("utf-8")) except utllib.error.URLError as e: print("time out") if hasattr(e,"code"): print(e.code)#状态码是多少 if hasattr(e,"reason"): print(e.reason)#错误的原因是什么