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()
相关文章
- 03-19async_retrying