本文整理匯總了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)
示例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"
)
示例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"
)
示例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)
示例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")
示例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")
示例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)
示例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)