Add some more diagnostics on server connection failure

This commit is contained in:
Paul Makepeace 2011-04-28 14:43:15 +00:00
parent 35bb7754be
commit b7e56fe203
1 changed files with 9 additions and 1 deletions

View File

@ -44,7 +44,15 @@ class RefineServer(object):
if data:
req.add_data(data) # data = urllib.urlencode(data)
#req.add_header('Accept-Encoding', 'gzip')
response = urllib2.urlopen(req)
try:
response = urllib2.urlopen(req)
except urllib2.URLError as (url_error,):
if 'Connection refused' in url_error:
raise urllib2.URLError(
'%s for %s. No Refine server reachable/running; ENV set?' %
(url_error, self.server))
else:
raise
if response.info().get('Content-Encoding', None) == 'gzip':
# Need a seekable filestream for gzip
gzip_fp = gzip.GzipFile(fileobj=StringIO.StringIO(response.read()))