python urllib2 timeout处理实例,pythonurllib2,python的urlli
python urllib2 timeout处理实例,pythonurllib2,python的urlli
python的urllib2包的timeout异常需要通过socket.timeout异常来捕获,如下实例:
import urllib2import socketclass MyException(Exception): passtry: urllib2.urlopen("http://example.com", timeout = 1)except urllib2.URLError, e: # For Python 2.6 if isinstance(e.reason, socket.timeout): raise MyException("There was an error: %r" % e) else: # reraise the original error raiseexcept socket.timeout, e: # For Python 2.7 raise MyException("There was an error: %r" % e)
相关内容
- python循环中的break continue使用,pythonbreak,count = 0whi
- python计算windows的cpu使用率,pythoncpu,import osdef
- python 多层list转为一层,python多层list转为,在c,c++等语
- python处理http post payload request类型请求,pythonpayload,普通
- python执行子进程, 设置命令输入,python命令,使用subp
- python minidom toxml方法,minidomtoxml,from xml.dom
- Mixed String type: normal string and unicode,mixedunicode,print 'ni
- Demonstrates the differences between the methods for importing module
- Built-in Numeric Tools,built-innumeric,import math
- Draw shape border,drawshapeborder,from Tkinter
评论关闭