// plain
Query parameters can be set with Python Aiohttp using the params
argument of the aiohttp.ClientSession.get()
method.
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)
200
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
group: aiohttp
onelinerhub: How to set query parameters with Python Aiohttp?