【发布时间】:2017-06-15 09:15:36
【问题描述】:
我在 Python 2.7 中的脚本每分钟抓取一个网站,但有时会报错:
urlopen 错误 [Errno 54] Connection reset by peer>
如何处理异常?我正在尝试这样的事情:
from socket import error as SocketError
import errno
try:
response = urllib2.urlopen(request).read()
except SocketError as e:
if e.errno != errno.ECONNRESET:
print "there is a time-out"
pass
print "There is no time-out, continue"
【问题讨论】: