From: Ben Darnell Date: Mon, 15 Sep 2014 03:55:59 +0000 (-0400) Subject: Update example for HTTPClient exception handling. X-Git-Tag: v4.1.0b1~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24c2f57704b82035a578a225f3d2a405491e4b82;p=thirdparty%2Ftornado.git Update example for HTTPClient exception handling. Eliminate the implication that HTTPError is the only error that can be raised. See #1168. --- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index c8ecf47c3..df4295171 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -63,7 +63,12 @@ class HTTPClient(object): response = http_client.fetch("http://www.google.com/") print response.body except httpclient.HTTPError as e: - print "Error:", e + # HTTPError is raised for non-200 responses; the response + # can be found in e.response. + print("Error: " + str(e)) + except Exception as e: + # Other errors are possible, such as IOError. + print("Error: " + str(e)) http_client.close() """ def __init__(self, async_client_class=None, **kwargs):