-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathex23.py
More file actions
27 lines (20 loc) · 717 Bytes
/
ex23.py
File metadata and controls
27 lines (20 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import platform
import aiohttp
import asyncio
from uuid import uuid4
async def main():
timeout = aiohttp.ClientTimeout(total=1)
async with aiohttp.ClientSession(
headers={"Request-Id": str(uuid4())},
timeout=timeout,
) 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()
return f"Body: {html[:15]}..."
if __name__ == "__main__":
if platform.system() == 'Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
r = asyncio.run(main())
print(r)