From b4dc970296be1f8e78c548424d3f3561db2d9410 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 6 Jul 2014 05:39:54 +0400 Subject: [PATCH] Handle HTTPException and IOError (socket errors) Log all errors. --- Robots/bkmk_rurllib2.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Robots/bkmk_rurllib2.py b/Robots/bkmk_rurllib2.py index b15a7b0..49c5568 100644 --- a/Robots/bkmk_rurllib2.py +++ b/Robots/bkmk_rurllib2.py @@ -14,7 +14,7 @@ __all__ = ['robot_urllib2'] import sys import httplib import urllib2 -from Robots.bkmk_robot_base import robot_base +from Robots.bkmk_robot_base import robot_base, get_error opener = urllib2.OpenerDirector() @@ -53,9 +53,19 @@ class robot_urllib2(robot_base): if e.code in (301, 302, 303, 307): return None, e.code, e.hdrs['Location'], None, None else: + self.log(' HTTP Error %s: %s' % (e.code, e.msg)) return "HTTP Error %s: %s" % (e.code, e.msg), None, None, None, None except urllib2.URLError, e: + self.log(' URL Error: %s' % e.reason) return "URL Error: %s" % e.reason, None, None, None, None + except httplib.HTTPException, e: + error = get_error(e) + self.log(' HTTP Exception: %s' % error) + return "HTTP Exception: %s" % error, None, None, None, None + except IOError, e: + error = get_error(e) + self.log(' I/O Error: %s' % error) + return "I/O Error: %s" % error, None, None, None, None else: return None, None, None, response.info(), response.read() -- 2.39.2