本文整理匯總了Python中tornado.httpclient.HTTPClient方法的典型用法代碼示例。如果您正苦於以下問題:Python httpclient.HTTPClient方法的具體用法?Python httpclient.HTTPClient怎麽用?Python httpclient.HTTPClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.httpclient
的用法示例。
在下文中一共展示了httpclient.HTTPClient方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def setUp(self):
if IOLoop.configured_class().__name__ in ('TwistedIOLoop',
'AsyncIOMainLoop'):
# TwistedIOLoop only supports the global reactor, so we can't have
# separate IOLoops for client and server threads.
# AsyncIOMainLoop doesn't work with the default policy
# (although it could with some tweaks to this test and a
# policy that created loops for non-main threads).
raise unittest.SkipTest(
'Sync HTTPClient not compatible with TwistedIOLoop or '
'AsyncIOMainLoop')
self.server_ioloop = IOLoop()
sock, self.port = bind_unused_port()
app = Application([('/', HelloWorldHandler)])
self.server = HTTPServer(app, io_loop=self.server_ioloop)
self.server.add_socket(sock)
self.server_thread = threading.Thread(target=self.server_ioloop.start)
self.server_thread.start()
self.http_client = HTTPClient()
示例2: setUp
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def setUp(self):
if IOLoop.configured_class().__name__ == 'TwistedIOLoop':
# TwistedIOLoop only supports the global reactor, so we can't have
# separate IOLoops for client and server threads.
raise unittest.SkipTest(
'Sync HTTPClient not compatible with TwistedIOLoop')
self.server_ioloop = IOLoop()
sock, self.port = bind_unused_port()
app = Application([('/', HelloWorldHandler)])
server = HTTPServer(app, io_loop=self.server_ioloop)
server.add_socket(sock)
self.server_thread = threading.Thread(target=self.server_ioloop.start)
self.server_thread.start()
self.http_client = HTTPClient()
示例3: setUp
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def setUp(self):
if IOLoop.configured_class().__name__ == 'TwistedIOLoop':
# TwistedIOLoop only supports the global reactor, so we can't have
# separate IOLoops for client and server threads.
raise unittest.SkipTest(
'Sync HTTPClient not compatible with TwistedIOLoop')
self.server_ioloop = IOLoop()
@gen.coroutine
def init_server():
sock, self.port = bind_unused_port()
app = Application([('/', HelloWorldHandler)])
self.server = HTTPServer(app)
self.server.add_socket(sock)
self.server_ioloop.run_sync(init_server)
self.server_thread = threading.Thread(target=self.server_ioloop.start)
self.server_thread.start()
self.http_client = HTTPClient()
示例4: send_request
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def send_request(url, max_sleep, validate_cert=True, username=None, password=None):
resp = None
for i in range(max_sleep):
time.sleep(i)
try:
req = HTTPRequest(
url,
method="GET",
auth_username=username,
auth_password=password,
validate_cert=validate_cert,
follow_redirects=True,
max_redirects=15,
)
resp = HTTPClient().fetch(req)
break
except Exception as e:
print(e)
pass
return resp
示例5: test_sync_client_error
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def test_sync_client_error(self):
# Synchronous HTTPClient raises errors directly; no need for
# response.rethrow()
with self.assertRaises(HTTPError) as assertion:
self.http_client.fetch(self.get_url('/notfound'))
self.assertEqual(assertion.exception.code, 404)
示例6: _CallService
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def _CallService(method, body, http_headers):
url = '%s%s' % (_BASE_URL, method)
return HTTPClient().fetch(url, method='POST', body=json.dumps(body), headers=http_headers,
validate_cert=False)
示例7: get
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def get(self):
# Use get_arguments for keys to get strings, but
# request.arguments for values to get bytes.
for k, v in zip(self.get_arguments('k'),
self.request.arguments['v']):
self.set_header(k, v)
# These tests end up getting run redundantly: once here with the default
# HTTPClient implementation, and then again in each implementation's own
# test suite.
示例8: register_volume
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def register_volume(self, volume):
# globally register volume
global volumes
volumes[volume.token] = volume
# globally register kernel client for this volume in the Jupyter server
cf = url_escape(find_connection_file())
http_client= HTTPClient()
try:
response = http_client.fetch(self.get_server_url() + '/register_token/' + volume.token.decode('utf8') + '/' + cf)
except Exception as e:
raise RuntimeError("could not register token: " + str(e))
http_client.close()
示例9: http_fetch
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPClient [as 別名]
def http_fetch(url):
""" Perform an HTTP request.
"""
from tornado.httpclient import HTTPClient
http_client = HTTPClient()
try:
response = http_client.fetch(url)
except Exception as err:
raise FetchError('http fetch failed: %s' % str(err))
finally:
http_client.close()
return response.body.decode()
# Prepare docss