python-aiohttpHow to use HTTP2 with Python Aiohttp?
HTTP2 can be used with Python Aiohttp by using the http2
parameter in the ClientSession
constructor.
import aiohttp
async with aiohttp.ClientSession(http2=True) as session:
async with session.get('https://example.com') as response:
print(response.status)
The output of the above code will be 200
.
Code explanation
import aiohttp
: This imports the aiohttp library.async with aiohttp.ClientSession(http2=True) as session
: This creates a ClientSession object with http2 enabled.async with session.get('https://example.com') as response
: This makes a GET request to the specified URL.print(response.status)
: This prints the response status code.
Helpful links
Related
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to make parallel requests with Python Aiohttp?
- How to set headers in Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to rate limit with Python Aiohttp?
- How to download large files with Python Aiohttp?
More of Python Aiohttp
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to get response text with Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to create a connection pool with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to rate limit with Python Aiohttp?
- How to get response code with Python Aiohttp?
- How to retry a request with Python Aiohttp?
See more codes...