Python tornado.httpclient.HTTPClient() Examples
The following are 20
code examples of tornado.httpclient.HTTPClient().
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: httpclient_test.py From tornado-zh with MIT License | 6 votes |
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()
Example #2
Source File: httpclient_test.py From tornado-zh with MIT License | 6 votes |
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()
Example #3
Source File: httpclient_test.py From EventGhost with GNU General Public License v2.0 | 6 votes |
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()
Example #4
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 6 votes |
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()
Example #5
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 6 votes |
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()
Example #6
Source File: httpclient_test.py From pySINDy with MIT License | 6 votes |
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()
Example #7
Source File: httpclient_test.py From teleport with Apache License 2.0 | 6 votes |
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()
Example #8
Source File: test_proxy.py From the-littlest-jupyterhub with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #9
Source File: httpclient_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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)
Example #10
Source File: __main__.py From flexx with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #11
Source File: viewer.py From nyroglancer with Apache License 2.0 | 5 votes |
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()
Example #12
Source File: httpclient_test.py From pySINDy with MIT License | 5 votes |
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)
Example #13
Source File: httpclient_test.py From pySINDy with MIT License | 5 votes |
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.
Example #14
Source File: httpclient_test.py From teleport with Apache License 2.0 | 5 votes |
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)
Example #15
Source File: httpclient_test.py From teleport with Apache License 2.0 | 5 votes |
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.
Example #16
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: run-ui-tests.py From viewfinder with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
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)
Example #19
Source File: httpclient_test.py From tornado-zh with MIT License | 5 votes |
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)
Example #20
Source File: httpclient_test.py From tornado-zh with MIT License | 5 votes |
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)