urllib.urlopen时出错,怎么把错误扑获让程序继续走下去

urllib.urlopen时出错,怎么把错误扑获让程序继续走下去

Traceback (most recent call last):
  File "getbook.py", line 53, in <module>
    fh = urllib.urlopen(thisurl)
  File "C:\software\python25\lib\urllib.py", line 82, in urlopen
    return opener.open(url)
  File "C:\software\python25\lib\urllib.py", line 190, in open
    return getattr(self, name)(url)
  File "C:\software\python25\lib\urllib.py", line 328, in open_http
    errcode, errmsg, headers = h.getreply()
  File "C:\software\python25\lib\httplib.py", line 1199, in getreply
    response = self._conn.getresponse()
  File "C:\software\python25\lib\httplib.py", line 928, in getresponse
    response.begin()
  File "C:\software\python25\lib\httplib.py", line 385, in begin
    version, status, reason = self._read_status()
  File "C:\software\python25\lib\httplib.py", line 343, in _read_status
    line = self.fp.readline()
  File "c:\software\python25\lib\socket.py", line 331, in readline
    data = recv(1)
IOError: [Errno socket error] (10054, 'Connection reset by peer')
try..except

碰到异常时候直接跳过,继续urllopen

谢谢,我已经修改了程序,把容易出错的代码放在try内了
连接被重置和超时不一样吧……
try……except……是正解。
这样的话会会那个出现在错误的url就给pass了呀,新手?
可以设置一个阈值,当try这个url阈值时,就跳过该url。
一点意见,大家多指教。