Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Fix example http_client #38

Merged
merged 1 commit into from
May 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/http_client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import asyncio
import aiohttp

async def fetch_page(session, url):
with aiohttp.Timeout(10):
async def fetch_page(url):
timeout = aiohttp.ClientTimeout(10)
async with aiohttp.ClientSession(loop=loop, timeout=timeout) as session:
async with session.get(url) as response:
assert response.status == 200
return await response.read()

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)
content = loop.run_until_complete(
fetch_page('http://python.org'))
print(content)
loop.close()