当前位置: 首页>>代码示例>>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;未经允许,请勿转载。