当前位置: 首页>>代码示例>>Python>>正文


Python tornado.httpclient方法代码示例

本文整理汇总了Python中tornado.httpclient方法的典型用法代码示例。如果您正苦于以下问题:Python tornado.httpclient方法的具体用法?Python tornado.httpclient怎么用?Python tornado.httpclient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado的用法示例。


在下文中一共展示了tornado.httpclient方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _start_download

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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) 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:http_download.py

示例2: http_client

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
def http_client(request, http_server):
    """Get an asynchronous HTTP client.
    """
    client = tornado.httpclient.AsyncHTTPClient()

    def _close():
        client.close()

    request.addfinalizer(_close)
    return client 
开发者ID:eugeniy,项目名称:pytest-tornado,代码行数:12,代码来源:plugin.py

示例3: https_client

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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 
开发者ID:eugeniy,项目名称:pytest-tornado,代码行数:13,代码来源:plugin.py

示例4: _request

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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) 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:9,代码来源:local_agent_net.py

示例5: test_get

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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) 
开发者ID:instana,项目名称:python-sensor,代码行数:59,代码来源:test_tornado_client.py

示例6: test_post

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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) 
开发者ID:instana,项目名称:python-sensor,代码行数:58,代码来源:test_tornado_client.py

示例7: test_get_405

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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) 
开发者ID:instana,项目名称:python-sensor,代码行数:61,代码来源:test_tornado_client.py

示例8: test_get_500

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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) 
开发者ID:instana,项目名称:python-sensor,代码行数:61,代码来源:test_tornado_client.py

示例9: test_get_504

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpclient [as 别名]
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) 
开发者ID:instana,项目名称:python-sensor,代码行数:61,代码来源:test_tornado_client.py


注:本文中的tornado.httpclient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。