diff options
author | W. Trevor King <wking@tremily.us> | 2012-08-24 08:07:46 -0400 |
---|---|---|
committer | W. Trevor King <wking@tremily.us> | 2012-08-24 09:32:43 -0400 |
commit | f0fe11190de73c153d7fb66734434ade4a21dbc2 (patch) | |
tree | 66b1a2ec0caa70ab0cfdd2ba023335938db271da | |
parent | 3e8b3e08cd9cbb99b44376a91fcfbef42ee3888e (diff) | |
download | bugseverywhere-f0fe11190de73c153d7fb66734434ade4a21dbc2.tar.gz |
util:http: convert urllib2.URLError into HTTPError in get_post_url.
Also rework liburl2.HTTPError handling to get both the reason and the
error code into the HTTPError message.
-rw-r--r-- | libbe/util/http.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libbe/util/http.py b/libbe/util/http.py index 2f15b15..b9b1765 100644 --- a/libbe/util/http.py +++ b/libbe/util/http.py @@ -83,12 +83,18 @@ def get_post_url(url, get=True, data_dict=None, headers=[], agent=None): try: response = urllib2.urlopen(req) except urllib2.HTTPError, e: + lines = [ + 'We failed to connect to the server (HTTPError).', + 'URL: {}'.format(url), + ] if hasattr(e, 'reason'): - msg = ('We failed to connect to the server.\nURL: {}\n' - 'Reason: {}').format(url, e.reason) - elif hasattr(e, 'code'): - msg = ("The server couldn't fulfill the request.\nURL: {}\n" - 'Error code: {}').format(url, e.code) + lines.append('Reason: {}'.format(e.reason)) + lines.append('Error code: {}'.format(e.code)) + msg = '\n'.join(lines) + raise HTTPError(error=e, url=url, msg=msg) + except urllib2.URLError, e: + msg = ('We failed to connect to the server (URLError).\nURL: {}\n' + 'Reason: {}').format(url, e.reason) raise HTTPError(error=e, url=url, msg=msg) page = response.read() final_url = response.geturl() |