flags2_await.py 文件源码

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

项目:Books_SourceCode 作者: activeion 项目源码 文件源码
def get_flag(base_url, cc): # <2>
    url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
    async with aiohttp.ClientSession() as session:         
        with async_timeout.timeout(10):         
            async with session.get(url) as resp:             
                if resp.status == 200:
                    image = await resp.read()  # <5>
                    return image
                elif resp.status == 404:
                    raise web.HTTPNotFound()
                else:
                    raise aiohttp.HttpProcessingError(
                        code=resp.status, message=resp.reason,
                        headers=resp.headers)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号