本文整理汇总了Python中tornado.simple_httpclient.SimpleAsyncHTTPClient.close方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleAsyncHTTPClient.close方法的具体用法?Python SimpleAsyncHTTPClient.close怎么用?Python SimpleAsyncHTTPClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.simple_httpclient.SimpleAsyncHTTPClient
的用法示例。
在下文中一共展示了SimpleAsyncHTTPClient.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: raw_fetch
# 需要导入模块: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
# 或者: from tornado.simple_httpclient.SimpleAsyncHTTPClient import close [as 别名]
def raw_fetch(self, headers, body):
client = SimpleAsyncHTTPClient(self.io_loop)
conn = RawRequestHTTPConnection(
self.io_loop, client, httpclient.HTTPRequest(self.get_url("/")), None, self.stop, 1024 * 1024
)
conn.set_request(b("\r\n").join(headers + [utf8("Content-Length: %d\r\n" % len(body))]) + b("\r\n") + body)
response = self.wait()
client.close()
response.rethrow()
return response
示例2: raw_fetch
# 需要导入模块: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
# 或者: from tornado.simple_httpclient.SimpleAsyncHTTPClient import close [as 别名]
def raw_fetch(self, headers, body):
client = SimpleAsyncHTTPClient(self.io_loop)
conn = RawRequestHTTPConnection(
self.io_loop, client,
httpclient._RequestProxy(
httpclient.HTTPRequest(self.get_url("/")),
dict(httpclient.HTTPRequest._DEFAULTS)),
None, self.stop,
1024 * 1024, Resolver(io_loop=self.io_loop))
conn.set_request(
b"\r\n".join(headers +
[utf8("Content-Length: %d\r\n" % len(body))]) +
b"\r\n" + body)
response = self.wait()
client.close()
response.rethrow()
return response
示例3: __init__
# 需要导入模块: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
# 或者: from tornado.simple_httpclient.SimpleAsyncHTTPClient import close [as 别名]
class AsyncHandler:
def __init__(self, link: str, loop: IOLoop = None, timeout: int = 50):
self.link = link
self.client = SimpleAsyncHTTPClient(loop)
self.timeout = timeout
if loop is None:
self.loop = IOLoop.current(False)
else:
self.loop = loop
self.header_only = False
def get_response(self, header_only=False):
self.header_only = header_only
# result = self.inner_get_response()
result = self.loop.run_sync(self.inner_get_response)
self.client.close()
return result
@gen.coroutine
def inner_get_response(self) -> (int, dict, str):
method = "GET"
if self.header_only:
method = "HEAD"
try:
req = HTTPRequest(
self.link,
headers=WebRequestCommonHeader.get_html_header(),
request_timeout=self.timeout,
follow_redirects=True,
method=method,
)
response = yield self.client.fetch(req)
# self.client.close()
return response.code, response.headers, response.body
except HTTPError as ex:
result = ex.response
# self.loop.stop()
return result.code, None, ""
except:
# self.loop.stop()
return 999, None, ""
finally:
pass
示例4: test_ip
# 需要导入模块: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
# 或者: from tornado.simple_httpclient.SimpleAsyncHTTPClient import close [as 别名]
def test_ip(ip):
hostname = APP_ID + '.appspot.com'
url = 'https://' + hostname + '/2'
request = HTTPRequest(url, request_timeout=5)
try:
client = SimpleAsyncHTTPClient(force_instance=True,
hostname_mapping={hostname: ip})
res = yield client.fetch(request, raise_error=False)
if isinstance(res.error, OSError):
if res.error.errno == errno.EMFILE:
warning_msg = ("Too many open files. You should increase the"
" maximum allowed number of network connections in you"
" system or decrease the CONCURRENCY setting.")
warnings.warn(warning_msg)
if res.code == 200:
return True
else:
return False
finally:
client.close()