Exceptions
----------
- .. autoexception:: HTTPError
+ .. autoexception:: HTTPClientError
:members:
+ .. exception:: HTTPError
+
+ Alias for `HTTPClientError`.
+
Command-line interface
----------------------
return "%s(%s)" % (self.__class__.__name__, args)
-class HTTPError(Exception):
+class HTTPClientError(Exception):
"""Exception thrown for an unsuccessful HTTP request.
Attributes:
Note that if ``follow_redirects`` is False, redirects become HTTPErrors,
and you can look at ``error.response.headers['Location']`` to see the
destination of the redirect.
+
+ .. versionchanged:: 5.1
+
+ Renamed from ``HTTPError`` to ``HTTPClientError`` to avoid collisions with
+ `tornado.web.HTTPError`. The name ``tornado.httpclient.HTTPError`` remains
+ as an alias.
"""
def __init__(self, code, message=None, response=None):
self.code = code
self.message = message or httputil.responses.get(code, "Unknown")
self.response = response
- super(HTTPError, self).__init__(code, message, response)
+ super(HTTPClientError, self).__init__(code, message, response)
def __str__(self):
return "HTTP %d: %s" % (self.code, self.message)
__repr__ = __str__
+HTTPError = HTTPClientError
+
+
class _RequestProxy(object):
"""Combines an object with a dictionary of defaults.
from __future__ import absolute_import, division, print_function
from tornado.concurrent import Future
-from tornado import gen, httpclient
+from tornado import gen
from tornado.escape import json_decode, utf8, to_unicode, recursive_unicode, native_str, to_basestring # noqa: E501
+from tornado.httpclient import HTTPClientError
from tornado.httputil import format_timestamp
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
with ExpectLog(gen_log,
"(Cannot send error response after headers written"
"|Failed to flush partial response)"):
- with self.assertRaises(httpclient.HTTPError):
+ with self.assertRaises(HTTPClientError):
self.fetch("/high", raise_error=True)
self.assertEqual(str(self.server_error),
"Tried to write 40 bytes less than Content-Length")
with ExpectLog(gen_log,
"(Cannot send error response after headers written"
"|Failed to flush partial response)"):
- with self.assertRaises(httpclient.HTTPError):
+ with self.assertRaises(HTTPClientError):
self.fetch("/low", raise_error=True)
self.assertEqual(str(self.server_error),
"Tried to write more data than Content-Length")