flags3_asyncio.py 文件源码

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

项目:notebooks 作者: fluentpython 项目源码 文件源码
def http_get(url):
    res = yield from aiohttp.request('GET', url)
    if res.status == 200:
        ctype = res.headers.get('Content-type', '').lower()
        if 'json' in ctype or url.endswith('json'):
            data = yield from res.json()  # <1>
        else:
            data = yield from res.read()  # <2>
        return data

    elif res.status == 404:
        raise web.HTTPNotFound()
    else:
        raise aiohttp.errors.HttpProcessingError(
            code=res.status, message=res.reason,
            headers=res.headers)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号