8000 Add first async request code sample. · gleme/complete-python-course@cb0669c · GitHub
[go: up one dir, main page]

Skip to content

Commit cb0669c

Browse files
committed
Add first async request code sample.
1 parent e02daac commit cb0669c

File tree

1 file changed

+11
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import aiohttp
2+
import asyncio
3+
4+
async def fetch_page(url):
5+
async with aiohttp.ClientSession() as session:
6+
async with session.get(url) as response:
7+
print(response.status)
8+
return response.status
9+
10+
loop = asyncio.get_event_loop()
11+
loop.run_until_complete(fetch_page('http://google.com'))