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

Commit 048b9c3

Browse files
authored
Merge pull request #38 from asyncio-docs/hoh-fix-example-http-client-issue-36
Fix example http_client
2 parents 8feba26 + de47def commit 048b9c3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

examples/http_client.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import asyncio
22
import aiohttp
33

4-
async def fetch_page(session, url):
5-
with aiohttp.Timeout(10):
4+
async def fetch_page(url):
5+
timeout = aiohttp.ClientTimeout(10)
6+
async with aiohttp.ClientSession(loop=loop, timeout=timeout) as session:
67
async with session.get(url) as response:
78
assert response.status == 200
89
return await response.read()
910

1011
loop = asyncio.get_event_loop()
11-
with aiohttp.ClientSession(loop=loop) as session:
12-
content = loop.run_until_complete(
13-
fetch_page(session, 'http://python.org'))
14-
print(content)
12+
content = loop.run_until_complete(
13+
fetch_page('http://python.org'))
14+
print(content)
1515
loop.close()

0 commit comments

Comments
 (0)