main.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:daytravel 作者: warsawpact 项目源码 文件源码
def request(host, path, bearer_token, params):
    """Given a bearer token, send a GET request to the API.

    Args:
        host (str): The domain host of the API.
        path (str): The path of the API after the domain.
        bearer_token (str): OAuth bearer token, obtained using client_id and client_secret.
        params (dict): An optional set of query parameters in the request.

    Returns:
        dict: The JSON response from the request.

    Raises:
        HTTPError: An error occurs from the HTTP request.
    """
    url = '{0}{1}?{2}'.format(
      host,
      quote(path.encode('utf8')),
      urllib.urlencode(params))
    headers = {
        'Authorization': 'Bearer %s' % bearer_token,
    }

    logging.info(u'Querying {0} ...'.format(url))
    result = urlfetch.fetch(
        url=url,
        method=urlfetch.GET,
        headers=headers)
    logging.info('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' + result.content)
    return json.loads(result.content)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号