async_retrying

from async_retrying import retry
import aiohttp
import asyncio


@retry(attempts=6)
async def fetch():
    print(1)
    async with aiohttp.ClientSession() as session:
        async with session.get("https://wwww.baidu.com", verify_ssl=False) as req:
            source = await req.text()
            1 / 0
            return source


async def main():
    res = await fetch()
    return res


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    try:
        res = loop.run_until_complete(main())
        print(res)
    finally:
        loop.close()

posted @ 2019-03-21 17:18  公众号python学习开发  阅读(832)  评论(0编辑  收藏  举报