python-aiohttpHow to set request cookies with Python Aiohttp?
Python Aiohttp library provides a convenient way to set request cookies.
import aiohttp
async with aiohttp.ClientSession() as session:
async with session.get('http://example.com', cookies={'name': 'value'}) as resp:
print(resp.status)
Output example
200
The code above sets a cookie with name name
and value value
in the request.
import aiohttp
imports the aiohttp library.async with aiohttp.ClientSession() as session
creates a client session.async with session.get('http://example.com', cookies={'name': 'value'}) as resp
sends a GET request tohttp://example.com
with the cookiename
set tovalue
.print(resp.status)
prints the response status code.
Helpful links
Related
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to create a connection pool with Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to close a Python Aiohttp session?
- How to rate limit 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 create a JSON response using Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- Bearer token request example with Python Aiohttp?
- How to rate limit with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to get response text with Python Aiohttp?
- How to retry a request with Python Aiohttp?
- How to make parallel requests with Python Aiohttp?
See more codes...