diff --git a/examples/http_client.py b/examples/http_client.py index 72987bf..20937c9 100644 --- a/examples/http_client.py +++ b/examples/http_client.py @@ -1,15 +1,14 @@ -import asyncio import aiohttp +import asyncio + +async def fetch(session, url): + async with session.get(url) as response: + return await response.text() -async def fetch_page(session, url): - with aiohttp.Timeout(10): - async with session.get(url) as response: - assert response.status == 200 - return await response.read() +async def main(): + async with aiohttp.ClientSession() as session: + html = await fetch(session, 'http://python.org') + print(html) loop = asyncio.get_event_loop() -with aiohttp.ClientSession(loop=loop) as session: - content = loop.run_until_complete( - fetch_page(session, 'http://python.org')) - print(content) -loop.close() +loop.run_until_complete(main())