Catch HTTP errors and report more diags

This commit is contained in:
Paul Makepeace 2013-10-13 00:34:10 +06:00
parent b92aa0efd1
commit a1ea660ffa
1 changed files with 4 additions and 2 deletions

View File

@ -81,10 +81,12 @@ class RefineServer(object):
#req.add_header('Accept-Encoding', 'gzip') #req.add_header('Accept-Encoding', 'gzip')
try: try:
response = urllib2.urlopen(req) 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( raise urllib2.URLError(
'%s for %s. No Refine server reachable/running; ENV set?' % '%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': if response.info().get('Content-Encoding', None) == 'gzip':
# Need a seekable filestream for gzip # Need a seekable filestream for gzip
gzip_fp = gzip.GzipFile(fileobj=StringIO.StringIO(response.read())) gzip_fp = gzip.GzipFile(fileobj=StringIO.StringIO(response.read()))