当前位置: 首页>>代码示例>>Python>>正文


Python httpclient.HTTPClientError方法代码示例

本文整理汇总了Python中tornado.httpclient.HTTPClientError方法的典型用法代码示例。如果您正苦于以下问题:Python httpclient.HTTPClientError方法的具体用法?Python httpclient.HTTPClientError怎么用?Python httpclient.HTTPClientError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.httpclient的用法示例。


在下文中一共展示了httpclient.HTTPClientError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:17,代码来源:auth_test.py

示例2: test_content_length_too_high

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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"
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:17,代码来源:web_test.py

示例3: test_content_length_too_low

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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"
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:17,代码来源:web_test.py

示例4: test_client_close

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:8,代码来源:web_test.py

示例5: test_content_length_too_high

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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") 
开发者ID:tp4a,项目名称:teleport,代码行数:14,代码来源:web_test.py

示例6: test_content_length_too_low

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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") 
开发者ID:tp4a,项目名称:teleport,代码行数:14,代码来源:web_test.py

示例7: test_client_close

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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) 
开发者ID:tp4a,项目名称:teleport,代码行数:8,代码来源:web_test.py

示例8: test_failed_setup

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPClientError [as 别名]
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) 
开发者ID:tp4a,项目名称:teleport,代码行数:16,代码来源:curl_httpclient_test.py


注:本文中的tornado.httpclient.HTTPClientError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。