Python tornado.httpclient() Examples
The following are 9
code examples of tornado.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
, or try the search function
.
Example #1
Source File: http_download.py From honeything with GNU General Public License v3.0 | 6 votes |
def _start_download(self): #print 'starting (auth_header=%r)' % self.auth_header ht.logger.info('starting (auth_header=%r)' % self.auth_header) if not self.tempfile: self.tempfile = tempfile.NamedTemporaryFile(delete=True, dir=self.download_dir) kwargs = dict(url=self.url, request_timeout=3600.0, streaming_callback=self.tempfile.write, use_gzip=True, allow_ipv6=True, user_agent='tr69-cpe-agent') if self.auth_header: kwargs.update(dict(headers=dict(Authorization=self.auth_header))) elif self.username and self.password: kwargs.update(dict(auth_username=self.username, auth_password=self.password)) req = tornado.httpclient.HTTPRequest(**kwargs) self.http_client = HTTPCLIENT(io_loop=self.ioloop) self.http_client.fetch(req, self._async_fetch_callback)
Example #2
Source File: plugin.py From pytest-tornado with Apache License 2.0 | 5 votes |
def http_client(request, http_server): """Get an asynchronous HTTP client. """ client = tornado.httpclient.AsyncHTTPClient() def _close(): client.close() request.addfinalizer(_close) return client
Example #3
Source File: plugin.py From pytest-tornado with Apache License 2.0 | 5 votes |
def https_client(request, https_server): """Get an asynchronous HTTPS client. """ # How does on get ca_certs from the user client = tornado.httpclient.AsyncHTTPClient() def _close(): client.close() request.addfinalizer(_close) return client
Example #4
Source File: local_agent_net.py From jaeger-client-python with Apache License 2.0 | 5 votes |
def _request(self, path, timeout=DEFAULT_TIMEOUT, args=None): http_client = tornado.httpclient.AsyncHTTPClient( defaults=dict(request_timeout=timeout)) url = 'http://%s:%d/%s' % (self.agent_http_host, self.agent_http_port, path) if args: url = url_concat(url, args) return http_client.fetch(url)
Example #5
Source File: test_tornado_client.py From python-sensor with MIT License | 4 votes |
def test_get(self): async def test(): with tornado_tracer.start_active_span('test'): return await self.http_client.fetch(testenv["tornado_server"] + "/") response = tornado.ioloop.IOLoop.current().run_sync(test) assert isinstance(response, tornado.httpclient.HTTPResponse) spans = self.recorder.queued_spans() self.assertEqual(3, len(spans)) server_span = spans[0] client_span = spans[1] test_span = spans[2] self.assertIsNone(tornado_tracer.active_span) # Same traceId traceId = test_span.t self.assertEqual(traceId, client_span.t) self.assertEqual(traceId, server_span.t) # Parent relationships self.assertEqual(client_span.p, test_span.s) self.assertEqual(server_span.p, client_span.s) # Error logging self.assertIsNone(test_span.ec) self.assertIsNone(client_span.ec) self.assertIsNone(server_span.ec) self.assertEqual("tornado-server", server_span.n) self.assertEqual(200, server_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/", server_span.data["http"]["url"]) self.assertIsNone(server_span.data["http"]["params"]) self.assertEqual("GET", server_span.data["http"]["method"]) self.assertIsNotNone(server_span.stack) self.assertTrue(type(server_span.stack) is list) self.assertTrue(len(server_span.stack) > 1) self.assertEqual("tornado-client", client_span.n) self.assertEqual(200, client_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/", client_span.data["http"]["url"]) self.assertEqual("GET", client_span.data["http"]["method"]) self.assertIsNotNone(client_span.stack) self.assertTrue(type(client_span.stack) is list) self.assertTrue(len(client_span.stack) > 1) assert("X-Instana-T" in response.headers) self.assertEqual(response.headers["X-Instana-T"], traceId) assert("X-Instana-S" in response.headers) self.assertEqual(response.headers["X-Instana-S"], server_span.s) assert("X-Instana-L" in response.headers) self.assertEqual(response.headers["X-Instana-L"], '1') assert("Server-Timing" in response.headers) self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)
Example #6
Source File: test_tornado_client.py From python-sensor with MIT License | 4 votes |
def test_post(self): async def test(): with tornado_tracer.start_active_span('test'): return await self.http_client.fetch(testenv["tornado_server"] + "/", method="POST", body='asdf') response = tornado.ioloop.IOLoop.current().run_sync(test) assert isinstance(response, tornado.httpclient.HTTPResponse) spans = self.recorder.queued_spans() self.assertEqual(3, len(spans)) server_span = spans[0] client_span = spans[1] test_span = spans[2] self.assertIsNone(tornado_tracer.active_span) # Same traceId traceId = test_span.t self.assertEqual(traceId, client_span.t) self.assertEqual(traceId, server_span.t) # Parent relationships self.assertEqual(client_span.p, test_span.s) self.assertEqual(server_span.p, client_span.s) # Error logging self.assertIsNone(test_span.ec) self.assertIsNone(client_span.ec) self.assertIsNone(server_span.ec) self.assertEqual("tornado-server", server_span.n) self.assertEqual(200, server_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/", server_span.data["http"]["url"]) self.assertIsNone(server_span.data["http"]["params"]) self.assertEqual("POST", server_span.data["http"]["method"]) self.assertIsNotNone(server_span.stack) self.assertTrue(type(server_span.stack) is list) self.assertTrue(len(server_span.stack) > 1) self.assertEqual("tornado-client", client_span.n) self.assertEqual(200, client_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/", client_span.data["http"]["url"]) self.assertEqual("POST", client_span.data["http"]["method"]) self.assertIsNotNone(client_span.stack) self.assertTrue(type(client_span.stack) is list) self.assertTrue(len(client_span.stack) > 1) assert("X-Instana-T" in response.headers) self.assertEqual(response.headers["X-Instana-T"], traceId) assert("X-Instana-S" in response.headers) self.assertEqual(response.headers["X-Instana-S"], server_span.s) assert("X-Instana-L" in response.headers) self.assertEqual(response.headers["X-Instana-L"], '1') assert("Server-Timing" in response.headers) self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)
Example #7
Source File: test_tornado_client.py From python-sensor with MIT License | 4 votes |
def test_get_405(self): async def test(): with tornado_tracer.start_active_span('test'): try: return await self.http_client.fetch(testenv["tornado_server"] + "/405") except tornado.httpclient.HTTPClientError as e: return e.response response = tornado.ioloop.IOLoop.current().run_sync(test) assert isinstance(response, tornado.httpclient.HTTPResponse) spans = self.recorder.queued_spans() self.assertEqual(3, len(spans)) server_span = spans[0] client_span = spans[1] test_span = spans[2] self.assertIsNone(tornado_tracer.active_span) # Same traceId traceId = test_span.t self.assertEqual(traceId, client_span.t) self.assertEqual(traceId, server_span.t) # Parent relationships self.assertEqual(client_span.p, test_span.s) self.assertEqual(server_span.p, client_span.s) # Error logging self.assertIsNone(test_span.ec) self.assertEqual(client_span.ec, 1) self.assertIsNone(server_span.ec) self.assertEqual("tornado-server", server_span.n) self.assertEqual(405, server_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/405", server_span.data["http"]["url"]) self.assertIsNone(server_span.data["http"]["params"]) self.assertEqual("GET", server_span.data["http"]["method"]) self.assertIsNotNone(server_span.stack) self.assertTrue(type(server_span.stack) is list) self.assertTrue(len(server_span.stack) > 1) self.assertEqual("tornado-client", client_span.n) self.assertEqual(405, client_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/405", client_span.data["http"]["url"]) self.assertEqual("GET", client_span.data["http"]["method"]) self.assertIsNotNone(client_span.stack) self.assertTrue(type(client_span.stack) is list) self.assertTrue(len(client_span.stack) > 1) assert("X-Instana-T" in response.headers) self.assertEqual(response.headers["X-Instana-T"], traceId) assert("X-Instana-S" in response.headers) self.assertEqual(response.headers["X-Instana-S"], server_span.s) assert("X-Instana-L" in response.headers) self.assertEqual(response.headers["X-Instana-L"], '1') assert("Server-Timing" in response.headers) self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)
Example #8
Source File: test_tornado_client.py From python-sensor with MIT License | 4 votes |
def test_get_500(self): async def test(): with tornado_tracer.start_active_span('test'): try: return await self.http_client.fetch(testenv["tornado_server"] + "/500") except tornado.httpclient.HTTPClientError as e: return e.response response = tornado.ioloop.IOLoop.current().run_sync(test) assert isinstance(response, tornado.httpclient.HTTPResponse) spans = self.recorder.queued_spans() self.assertEqual(3, len(spans)) server_span = spans[0] client_span = spans[1] test_span = spans[2] self.assertIsNone(tornado_tracer.active_span) # Same traceId traceId = test_span.t self.assertEqual(traceId, client_span.t) self.assertEqual(traceId, server_span.t) # Parent relationships self.assertEqual(client_span.p, test_span.s) self.assertEqual(server_span.p, client_span.s) # Error logging self.assertIsNone(test_span.ec) self.assertEqual(client_span.ec, 1) self.assertEqual(server_span.ec, 1) self.assertEqual("tornado-server", server_span.n) self.assertEqual(500, server_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/500", server_span.data["http"]["url"]) self.assertIsNone(server_span.data["http"]["params"]) self.assertEqual("GET", server_span.data["http"]["method"]) self.assertIsNotNone(server_span.stack) self.assertTrue(type(server_span.stack) is list) self.assertTrue(len(server_span.stack) > 1) self.assertEqual("tornado-client", client_span.n) self.assertEqual(500, client_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/500", client_span.data["http"]["url"]) self.assertEqual("GET", client_span.data["http"]["method"]) self.assertIsNotNone(client_span.stack) self.assertTrue(type(client_span.stack) is list) self.assertTrue(len(client_span.stack) > 1) assert("X-Instana-T" in response.headers) self.assertEqual(response.headers["X-Instana-T"], traceId) assert("X-Instana-S" in response.headers) self.assertEqual(response.headers["X-Instana-S"], server_span.s) assert("X-Instana-L" in response.headers) self.assertEqual(response.headers["X-Instana-L"], '1') assert("Server-Timing" in response.headers) self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)
Example #9
Source File: test_tornado_client.py From python-sensor with MIT License | 4 votes |
def test_get_504(self): async def test(): with tornado_tracer.start_active_span('test'): try: return await self.http_client.fetch(testenv["tornado_server"] + "/504") except tornado.httpclient.HTTPClientError as e: return e.response response = tornado.ioloop.IOLoop.current().run_sync(test) assert isinstance(response, tornado.httpclient.HTTPResponse) spans = self.recorder.queued_spans() self.assertEqual(3, len(spans)) server_span = spans[0] client_span = spans[1] test_span = spans[2] self.assertIsNone(tornado_tracer.active_span) # Same traceId traceId = test_span.t self.assertEqual(traceId, client_span.t) self.assertEqual(traceId, server_span.t) # Parent relationships self.assertEqual(client_span.p, test_span.s) self.assertEqual(server_span.p, client_span.s) # Error logging self.assertIsNone(test_span.ec) self.assertEqual(client_span.ec, 1) self.assertEqual(server_span.ec, 1) self.assertEqual("tornado-server", server_span.n) self.assertEqual(504, server_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/504", server_span.data["http"]["url"]) self.assertIsNone(server_span.data["http"]["params"]) self.assertEqual("GET", server_span.data["http"]["method"]) self.assertIsNotNone(server_span.stack) self.assertTrue(type(server_span.stack) is list) self.assertTrue(len(server_span.stack) > 1) self.assertEqual("tornado-client", client_span.n) self.assertEqual(504, client_span.data["http"]["status"]) self.assertEqual(testenv["tornado_server"] + "/504", client_span.data["http"]["url"]) self.assertEqual("GET", client_span.data["http"]["method"]) self.assertIsNotNone(client_span.stack) self.assertTrue(type(client_span.stack) is list) self.assertTrue(len(client_span.stack) > 1) assert("X-Instana-T" in response.headers) self.assertEqual(response.headers["X-Instana-T"], traceId) assert("X-Instana-S" in response.headers) self.assertEqual(response.headers["X-Instana-S"], server_span.s) assert("X-Instana-L" in response.headers) self.assertEqual(response.headers["X-Instana-L"], '1') assert("Server-Timing" in response.headers) self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)