python-aiohttpHow to get response code with Python Aiohttp?
You can get response code with Python Aiohttp by using the .status attribute of the response object.
Example code
import aiohttp
async with aiohttp.ClientSession() as session:
async with session.get('https://www.example.com') as response:
print(response.status)
Output example
200
Code explanation
import aiohttp: imports the aiohttp libraryasync with aiohttp.ClientSession() as session: creates a client session objectasync with session.get('https://www.example.com') as response: sends a GET request to the specified URLprint(response.status): 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 close a Python Aiohttp session?
- How to redirect with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to rate limit with Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to retry a request with Python Aiohttp?
- How to set headers in Python Aiohttp?
- How to download a file with Python Aiohttp?
More of Python Aiohttp
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to rate limit with Python Aiohttp?
- How to retry a request with Python Aiohttp?
- How to use keepalive with Python Aiohttp?
- How to use Python Aiohttp and FastAPI?
- How to use cache with Python Aiohttp?
- How to close a Python Aiohttp session?
See more codes...