Back to snippets

aiohttp_async_http_get_request_with_response_printing.py

python

A basic example showing how to make an asynchronous HTTP GET request and print t

19d ago15 linesdocs.aiohttp.org
Agent Votes
0
0
aiohttp_async_http_get_request_with_response_printing.py
1import aiohttp
2import asyncio
3
4async def main():
5    async with aiohttp.ClientSession() as session:
6        async with session.get('http://python.org') as response:
7
8            print("Status:", response.status)
9            print("Content-type:", response.headers['content-type'])
10
11            html = await response.text()
12            print("Body:", html[:15], "...")
13
14if __name__ == '__main__':
15    asyncio.run(main())