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


Python httpclient.HTTPClient方法代码示例

本文整理汇总了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() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:24,代码来源:httpclient_test.py

示例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() 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:19,代码来源:httpclient_test.py

示例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() 
开发者ID:tp4a,项目名称:teleport,代码行数:22,代码来源:httpclient_test.py

示例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 
开发者ID:jupyterhub,项目名称:the-littlest-jupyterhub,代码行数:23,代码来源:test_proxy.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:httpclient_test.py

示例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) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:6,代码来源:run-ui-tests.py

示例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. 
开发者ID:tp4a,项目名称:teleport,代码行数:12,代码来源:httpclient_test.py

示例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() 
开发者ID:funkey,项目名称:nyroglancer,代码行数:16,代码来源:viewer.py

示例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 
开发者ID:flexxui,项目名称:flexx,代码行数:17,代码来源:__main__.py


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