Cookies in Python
If you want to use cookies in web development, requests library is a very wise choice.
If a response contains some Cookies, you can get quick access to them:
If you want to send your own cookies to server, you can simple add cookies
parameters:
If you want to set the domain
or path
value in cookies, just add them into the cookies
dict which you created before.
Also, you can use create_cookie
method that requests supplies, you can import it by from requests.cookies import create_cookie
, it will exactly do the same job.
The cookies created are instances of cookielib.Cookie
, they are held by requests.cookies.RequestsCookieJar
.
requests is a very useful library, and what’s more, it is simple. Go to requests to see more.