當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。