Python tornado.httpclient.HTTPClientError() Examples

The following are 16 code examples of tornado.httpclient.HTTPClientError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tornado.httpclient , or try the search function .
Example #1
Source File: auth_test.py    From opendevops with GNU General Public License v3.0 5 votes vote down vote up
def get(self):
        # TODO: would be nice to go through the login flow instead of
        # cheating with a hard-coded access token.
        try:
            response = yield self.twitter_request(
                "/users/show/%s" % self.get_argument("name"),
                access_token=dict(key="hjkl", secret="vbnm"),
            )
        except HTTPClientError:
            # TODO(bdarnell): Should we catch HTTP errors and
            # transform some of them (like 403s) into AuthError?
            self.set_status(500)
            self.finish("error from twitter request")
        else:
            self.finish(response) 
Example #2
Source File: web_test.py    From opendevops with GNU General Public License v3.0 5 votes vote down vote up
def test_content_length_too_high(self):
        # When the content-length is too high, the connection is simply
        # closed without completing the response.  An error is logged on
        # the server.
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(
                gen_log,
                "(Cannot send error response after headers written"
                "|Failed to flush partial response)",
            ):
                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"
        ) 
Example #3
Source File: web_test.py    From opendevops with GNU General Public License v3.0 5 votes vote down vote up
def test_content_length_too_low(self):
        # When the content-length is too low, the connection is closed
        # without writing the last chunk, so the client never sees the request
        # complete (which would be a framing error).
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(
                gen_log,
                "(Cannot send error response after headers written"
                "|Failed to flush partial response)",
            ):
                with self.assertRaises(HTTPClientError):
                    self.fetch("/low", raise_error=True)
        self.assertEqual(
            str(self.server_error), "Tried to write more data than Content-Length"
        ) 
Example #4
Source File: web_test.py    From opendevops with GNU General Public License v3.0 5 votes vote down vote up
def test_client_close(self):
        with self.assertRaises((HTTPClientError, unittest.SkipTest)):
            response = self.fetch("/", raise_error=True)
            if response.body == b"requires HTTP/1.x":
                self.skipTest("requires HTTP/1.x")
            self.assertEqual(response.code, 599) 
Example #5
Source File: web_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_content_length_too_high(self):
        # When the content-length is too high, the connection is simply
        # closed without completing the response.  An error is logged on
        # the server.
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(gen_log,
                           "(Cannot send error response after headers written"
                           "|Failed to flush partial response)"):
                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") 
Example #6
Source File: web_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_content_length_too_low(self):
        # When the content-length is too low, the connection is closed
        # without writing the last chunk, so the client never sees the request
        # complete (which would be a framing error).
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(gen_log,
                           "(Cannot send error response after headers written"
                           "|Failed to flush partial response)"):
                with self.assertRaises(HTTPClientError):
                    self.fetch("/low", raise_error=True)
        self.assertEqual(str(self.server_error),
                         "Tried to write more data than Content-Length") 
Example #7
Source File: web_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_client_close(self):
        with self.assertRaises((HTTPClientError, unittest.SkipTest)):
            response = self.fetch('/', raise_error=True)
            if response.body == b'requires HTTP/1.x':
                self.skipTest('requires HTTP/1.x')
            self.assertEqual(response.code, 599) 
Example #8
Source File: curl_httpclient_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_failed_setup(self):
        self.http_client = self.create_client(max_clients=1)
        for i in range(5):
            with ignore_deprecation():
                response = self.fetch(u'/ユニコード')
            self.assertIsNot(response.error, None)

            with self.assertRaises((UnicodeEncodeError, HTTPClientError)):
                # This raises UnicodeDecodeError on py3 and
                # HTTPClientError(404) on py2. The main motivation of
                # this test is to ensure that the UnicodeEncodeError
                # during the setup phase doesn't lead the request to
                # be dropped on the floor.
                response = self.fetch(u'/ユニコード', raise_error=True) 
Example #9
Source File: web_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_content_length_too_high(self):
        # When the content-length is too high, the connection is simply
        # closed without completing the response.  An error is logged on
        # the server.
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(gen_log,
                           "(Cannot send error response after headers written"
                           "|Failed to flush partial response)"):
                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") 
Example #10
Source File: web_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_content_length_too_low(self):
        # When the content-length is too low, the connection is closed
        # without writing the last chunk, so the client never sees the request
        # complete (which would be a framing error).
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(gen_log,
                           "(Cannot send error response after headers written"
                           "|Failed to flush partial response)"):
                with self.assertRaises(HTTPClientError):
                    self.fetch("/low", raise_error=True)
        self.assertEqual(str(self.server_error),
                         "Tried to write more data than Content-Length") 
Example #11
Source File: web_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_client_close(self):
        with self.assertRaises((HTTPClientError, unittest.SkipTest)):
            response = self.fetch('/', raise_error=True)
            if response.body == b'requires HTTP/1.x':
                self.skipTest('requires HTTP/1.x')
            self.assertEqual(response.code, 599) 
Example #12
Source File: curl_httpclient_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_failed_setup(self):
        self.http_client = self.create_client(max_clients=1)
        for i in range(5):
            with ignore_deprecation():
                response = self.fetch(u'/ユニコード')
            self.assertIsNot(response.error, None)

            with self.assertRaises((UnicodeEncodeError, HTTPClientError)):
                # This raises UnicodeDecodeError on py3 and
                # HTTPClientError(404) on py2. The main motivation of
                # this test is to ensure that the UnicodeEncodeError
                # during the setup phase doesn't lead the request to
                # be dropped on the floor.
                response = self.fetch(u'/ユニコード', raise_error=True) 
Example #13
Source File: auth_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def get(self):
        # TODO: would be nice to go through the login flow instead of
        # cheating with a hard-coded access token.
        try:
            response = yield self.twitter_request(
                "/users/show/%s" % self.get_argument("name"),
                access_token=dict(key="hjkl", secret="vbnm"),
            )
        except HTTPClientError:
            # TODO(bdarnell): Should we catch HTTP errors and
            # transform some of them (like 403s) into AuthError?
            self.set_status(500)
            self.finish("error from twitter request")
        else:
            self.finish(response) 
Example #14
Source File: web_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def test_content_length_too_high(self):
        # When the content-length is too high, the connection is simply
        # closed without completing the response.  An error is logged on
        # the server.
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(
                gen_log,
                "(Cannot send error response after headers written"
                "|Failed to flush partial response)",
            ):
                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"
        ) 
Example #15
Source File: web_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def test_content_length_too_low(self):
        # When the content-length is too low, the connection is closed
        # without writing the last chunk, so the client never sees the request
        # complete (which would be a framing error).
        with ExpectLog(app_log, "(Uncaught exception|Exception in callback)"):
            with ExpectLog(
                gen_log,
                "(Cannot send error response after headers written"
                "|Failed to flush partial response)",
            ):
                with self.assertRaises(HTTPClientError):
                    self.fetch("/low", raise_error=True)
        self.assertEqual(
            str(self.server_error), "Tried to write more data than Content-Length"
        ) 
Example #16
Source File: web_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def test_client_close(self):
        with self.assertRaises((HTTPClientError, unittest.SkipTest)):
            response = self.fetch("/", raise_error=True)
            if response.body == b"requires HTTP/1.x":
                self.skipTest("requires HTTP/1.x")
            self.assertEqual(response.code, 599)