From a1ea660ffaf646378b520850ea3ea63d36d5bcc2 Mon Sep 17 00:00:00 2001 From: Paul Makepeace Date: Sun, 13 Oct 2013 00:34:10 +0600 Subject: [PATCH] Catch HTTP errors and report more diags --- google/refine/refine.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google/refine/refine.py b/google/refine/refine.py index e5ef1bf..3206f7a 100644 --- a/google/refine/refine.py +++ b/google/refine/refine.py @@ -81,10 +81,12 @@ class RefineServer(object): #req.add_header('Accept-Encoding', 'gzip') try: response = urllib2.urlopen(req) - except urllib2.URLError as (url_error,): + except urllib2.HTTPError as e: + raise Exception('HTTP %d "%s" for %s\n\t%s' % (e.code, e.msg, e.geturl(), data)) + except urllib2.URLError as e: raise urllib2.URLError( '%s for %s. No Refine server reachable/running; ENV set?' % - (url_error, self.server)) + (e.reason, self.server)) if response.info().get('Content-Encoding', None) == 'gzip': # Need a seekable filestream for gzip gzip_fp = gzip.GzipFile(fileobj=StringIO.StringIO(response.read()))