超时处理
Demo
#!/usr/bin/python3
import urllib.request,urllib.error,urllib.parse
#超时处理
#timeout:时间门限,响应时间超过此门限,则视为超时
try:
response=urllib.request.urlopen("http://httpbin.org/get",timeout=1)
print(response.read().decode("utf-8"))
except urllib.error.URLError as e:
print("超时!!!")
运行结果