當前位置: 首頁>>代碼示例>>Python>>正文


Python httpclient.AsyncHTTPClient方法代碼示例

本文整理匯總了Python中tornado.httpclient.AsyncHTTPClient方法的典型用法代碼示例。如果您正苦於以下問題:Python httpclient.AsyncHTTPClient方法的具體用法?Python httpclient.AsyncHTTPClient怎麽用?Python httpclient.AsyncHTTPClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.httpclient的用法示例。


在下文中一共展示了httpclient.AsyncHTTPClient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_links_from_url

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get_links_from_url(url):
    """Download the page at `url` and parse it for links.

    Returned links have had the fragment after `#` removed, and have been made
    absolute so, e.g. the URL 'gen.html#tornado.gen.coroutine' becomes
    'http://www.tornadoweb.org/en/stable/gen.html'.
    """
    try:
        response = yield httpclient.AsyncHTTPClient().fetch(url)
        print('fetched %s' % url)

        html = response.body if isinstance(response.body, str) \
            else response.body.decode()
        urls = [urljoin(url, remove_fragment(new_url))
                for new_url in get_links(html)]
    except Exception as e:
        print('Exception: %s %s' % (e, url))
        raise gen.Return([])

    raise gen.Return(urls) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:22,代碼來源:webspider.py

示例2: get_request

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get_request(self, url, headers=None):
        response = None
        http_client = AsyncHTTPClient()
        try:
            # response = yield http_client.fetch(url, method='GET', headers=headers,request_timeout=5)

            # POST
            body = {'a': 4, 'b': 5}
            response: HTTPResponse = yield http_client.fetch(url, method='POST', body=str(body), headers=headers, request_timeout=5)
        except Exception as e:
            print('get_request error:{0}'.format(e))

        #請求
        response.request
        #請求頭
        response.headers

        response_body = None
        if response and response.code == 200:
            # print('fetched {0}'.format(url))
            response_body = response.body if isinstance(response.body, str) \
                else response.body.decode()

        return response_body 
開發者ID:makelove,項目名稱:Python_Master_Courses,代碼行數:26,代碼來源:tornado-crawler-demo2.py

示例3: get_links_from_url

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get_links_from_url(url):
    """Download the page at `url` and parse it for links.

    Returned links have had the fragment after `#` removed, and have been made
    absolute so, e.g. the URL 'gen.html#tornado.gen.coroutine' becomes
    'http://www.tornadoweb.org/en/stable/gen.html'.
    """
    try:
        response = yield httpclient.AsyncHTTPClient().fetch(url)#獲取到
        print('fetched %s' % url)


        html = response.body if isinstance(response.body, str) \
            else response.body.decode()
        urls = [urljoin(url, remove_fragment(new_url))
                for new_url in get_links(html)]
    except Exception as e:
        print('Exception: %s %s' % (e, url))
        raise gen.Return([])

    raise gen.Return(urls) 
開發者ID:makelove,項目名稱:Python_Master_Courses,代碼行數:23,代碼來源:tornado-crawler-demo1.py

示例4: __init__

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def __init__(self, state_change_callback):
        # set properties
        self.state_change_callback = state_change_callback

        # load mappings
        self.SERVER_TYPES = parse_json_file(
            os.path.join(CURRENT_PATH, 'mapping/server_types.json'))
        self.REGIONS = parse_json_file(
            os.path.join(CURRENT_PATH, 'mapping/regions.json'))

        # set private vars
        self.API_URL = ("https://ws.ovh.com/dedicated/r2/ws.dispatcher"
                        "/getAvailability2")
        self.STATES = {}
        self.HTTP_ERRORS = []
        self.interval = 8   # seconds between interations
        self.periodic_cb = None
        self.ioloop = None
        self.http_client = AsyncHTTPClient() 
開發者ID:MA3STR0,項目名稱:kimsufi-crawler,代碼行數:21,代碼來源:crawler.py

示例5: revoke_service_tokens

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def revoke_service_tokens(self, services):
        """Revoke live Globus access and refresh tokens. Revoking inert or
        non-existent tokens does nothing. Services are defined by dicts
        returned by tokens.by_resource_server, for example:
        services = { 'transfer.api.globus.org': {'access_token': 'token'}, ...
            <Additional services>...
        }
        """
        access_tokens = [token_dict.get('access_token') for token_dict in services.values()]
        refresh_tokens = [token_dict.get('refresh_token') for token_dict in services.values()]
        all_tokens = [tok for tok in access_tokens + refresh_tokens if tok is not None]
        http_client = AsyncHTTPClient()
        for token in all_tokens:
            req = HTTPRequest(self.revocation_url,
                              method="POST",
                              headers=self.get_client_credential_headers(),
                              body=urllib.parse.urlencode({'token': token}),
                              )
            await http_client.fetch(req) 
開發者ID:jupyterhub,項目名稱:oauthenticator,代碼行數:21,代碼來源:globus.py

示例6: authenticate

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def authenticate(self, handler, data=None):
        code = handler.get_argument("code", False)
        if not code:
            raise web.HTTPError(400, "Authentication Cancelled.")
        http_client = AsyncHTTPClient()
        auth_request = self.get_auth_request(code)
        response = await http_client.fetch(auth_request)
        if not response:
            raise web.HTTPError(500, 'Authentication Failed: Token Not Acquired')
        state = json.loads(response.body.decode('utf8', 'replace'))
        access_token = state['access_token']
        info_request = self.get_user_info_request(access_token)
        response = await http_client.fetch(info_request)
        user = json.loads(response.body.decode('utf8', 'replace'))
        # TODO: preserve state in auth_state when JupyterHub supports encrypted auth_state
        return {
            'name': user['email'],
            'auth_state': {'access_token': access_token, 'okpy_user': user},
        } 
開發者ID:jupyterhub,項目名稱:oauthenticator,代碼行數:21,代碼來源:okpy.py

示例7: __init__

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def __init__(self, *args, **kwargs):
        super(HTTPClient, self).__init__(*args, **kwargs)
        self.client = httpclient.AsyncHTTPClient() 
開發者ID:poppyred,項目名稱:python-consul2,代碼行數:5,代碼來源:tornado.py

示例8: get_auth_http_client

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get_auth_http_client(self):
        """Returns the `.AsyncHTTPClient` instance to be used for auth requests.

        May be overridden by subclasses to use an HTTP client other than
        the default.
        """
        return httpclient.AsyncHTTPClient() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:9,代碼來源:auth.py

示例9: get_http_client

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get_http_client(self):
        return AsyncHTTPClient(io_loop=self.io_loop) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:4,代碼來源:testing.py

示例10: get

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get(self):
        io_loop = self.request.connection.stream.io_loop
        client = AsyncHTTPClient(io_loop=io_loop)
        response = yield gen.Task(client.fetch, self.get_argument('url'))
        response.rethrow()
        self.finish(b"got response: " + response.body) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:8,代碼來源:gen_test.py

示例11: tornado_fetch

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def tornado_fetch(self, url, runner):
        responses = []
        client = AsyncHTTPClient(self.io_loop)

        def callback(response):
            responses.append(response)
            self.stop_loop()
        client.fetch(url, callback=callback)
        runner()
        self.assertEqual(len(responses), 1)
        responses[0].rethrow()
        return responses[0] 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:14,代碼來源:twisted_test.py

示例12: fetch

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def fetch(self, path, **kwargs):
        """Convenience method to synchronously fetch a url.

        The given path will be appended to the local server's host and
        port.  Any additional kwargs will be passed directly to
        `.AsyncHTTPClient.fetch` (and so could be used to pass
        ``method="POST"``, ``body="..."``, etc).
        """
        self.http_client.fetch(self.get_url(path), self.stop, **kwargs)
        return self.wait() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:12,代碼來源:testing.py

示例13: fetch

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def fetch(url):
    print('fetcing', url)
    response = yield AsyncHTTPClient().fetch(url, raise_error=False)

    #POST

    raise gen.Return(response) 
開發者ID:makelove,項目名稱:Python_Master_Courses,代碼行數:9,代碼來源:tornado-async-spider.py

示例14: get_authenticated_user

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get_authenticated_user(
        self, http_client: httpclient.AsyncHTTPClient = None
    ) -> Dict[str, Any]:
        """Fetches the authenticated user data upon redirect.

        This method should be called by the handler that receives the
        redirect from the `authenticate_redirect()` method (which is
        often the same as the one that calls it; in that case you would
        call `get_authenticated_user` if the ``openid.mode`` parameter
        is present and `authenticate_redirect` if it is not).

        The result of this method will generally be used to set a cookie.

        .. versionchanged:: 6.0

            The ``callback`` argument was removed. Use the returned
            awaitable object instead.
        """
        handler = cast(RequestHandler, self)
        # Verify the OpenID response via direct request to the OP
        args = dict(
            (k, v[-1]) for k, v in handler.request.arguments.items()
        )  # type: Dict[str, Union[str, bytes]]
        args["openid.mode"] = u"check_authentication"
        url = self._OPENID_ENDPOINT  # type: ignore
        if http_client is None:
            http_client = self.get_auth_http_client()
        resp = await http_client.fetch(
            url, method="POST", body=urllib.parse.urlencode(args)
        )
        return self._on_authentication_verified(resp) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:33,代碼來源:auth.py

示例15: get_auth_http_client

# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import AsyncHTTPClient [as 別名]
def get_auth_http_client(self) -> httpclient.AsyncHTTPClient:
        """Returns the `.AsyncHTTPClient` instance to be used for auth requests.

        May be overridden by subclasses to use an HTTP client other than
        the default.
        """
        return httpclient.AsyncHTTPClient() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:9,代碼來源:auth.py


注:本文中的tornado.httpclient.AsyncHTTPClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。