python-aiohttpHow to set query parameters with Python Aiohttp?
Query parameters can be set with Python Aiohttp using the params
argument of the aiohttp.ClientSession.get()
method.
Example code
import aiohttp
async with aiohttp.ClientSession() as session:
params = {'key1': 'value1', 'key2': 'value2'}
async with session.get('http://example.com', params=params) as resp:
print(resp.status)
Output example
200
Code explanation
import aiohttp
- imports the aiohttp libraryasync with aiohttp.ClientSession() as session
- creates a client sessionparams = {'key1': 'value1', 'key2': 'value2'}
- creates a dictionary of query parametersasync with session.get('http://example.com', params=params) as resp
- sends a GET request to the specified URL with the query parametersprint(resp.status)
- prints the response status code
Helpful links
Related
- How to create a websocket server using Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to create a connection pool with Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to close a Python Aiohttp session?
- How to get response code with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to make request with basic HTTP auth using Python Aiohttp?
More of Python Aiohttp
- How to create a websocket server using Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to get response code with Python Aiohttp?
- How to rate limit with Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to get a response with Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to retry a request with Python Aiohttp?
See more codes...