util.py 文件源码

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

项目:NUST-API 作者: NUST-MSC 项目源码 文件源码
def async_fetch(url, headers=None, method="GET", data=None, follow_redirects=False):
    """
    Async http fetch
    :param url:
    :param headers:
    :param method:
    :param data:
    :param follow_redirects:
    """
    client = HTTPClient()
    headers = headers or {}
    body = None
    if method == "GET" and data is not None:
        url = url + '?' + urlencode(data)
    elif method == "POST" and data is not None:
        headers.update({'Content-Type': 'application/x-www-form-urlencoded'})
        body = urlencode(data)
    request = HTTPRequest(url=url, headers=headers,
                          method=method, follow_redirects=follow_redirects,
                          body=body)
    response = yield client.fetch(request, raise_error=False)
    # return response
    raise gen.Return(response)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号