The aiohttp response object contains all the information sent back from a web server after an aiohttp request. Getting familiar with the response object helps you better handle and process responses in your asynchronous Python code.
When you make a request using aiohttp, such as:
async with aiohttp.ClientSession() as session:
async with session.get('https://api.example.com') as response:
# response object returned here
The object returned and assigned to the
So for example, you can print the response status code, get a header value, and process the JSON response body with:
print(response.status)
content_type = response.headers['Content-Type']
data = await response.json()
The response object also contains some convenience properties like
When handling responses, be sure to:
Working with the aiohttp response object helps make it easier to write asynchronous Python clients and web applications. The key is becoming familiar with accessing response attributes like the status, headers, content, and using async methods like