-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex19.py
More file actions
22 lines (14 loc) · 559 Bytes
/
ex19.py
File metadata and controls
22 lines (14 loc) · 559 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import platform
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('https://python.org') as response:
print("Status:", response.status)
print("Content-type:", response.headers['content-type'])
html = await response.text()
print("Body:", html[:15], "...")
if __name__ == "__main__":
if platform.system() == 'Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())