I'm using the new Python Requests library to make http requests. I obtain a cookie from the server as text. How do I turn that into a CookieJar
with the cookie in it?
Keep Your Cookies In An Airtight ContainerTo make this kind of cookie jar airtight, just slip your cookies in a zipper-lock bag before you put them in your jar. Once you've selected your cookie container, and you're ready to stash your cookies, try layering them.
The fat in cookies tends to turn rancid, and the flour becomes stale for cookies in an unsealed cookie jar. Because bacteria, humidity, dirt, and dust can reach the cookies, causing the cookies to grow moldy and unpalatable.
#!/usr/bin/python print "Set-Cookie:UserID = XYZ;\r\n" print "Set-Cookie:Password = XYZ123;\r\n" print "Set-Cookie:Expires = Tuesday, 31-Dec-2007 23:12:40 GMT";\r\n" print "Set-Cookie:Domain = www.tutorialspoint.com;\r\n" print "Set-Cookie:Path = /perl;\n" print "Content-type:text/html\r\n\r\n" ...........
I'm confused by this question. The requests library will put the cookies in the jar for you.
import requests import cookielib URL = '...whatever...' jar = cookielib.CookieJar() r = requests.get(URL, cookies=jar) r = requests.get(URL, cookies=jar)
The first request to the URL will fill the jar. The second request will send the cookies back to the server. The same goes for the standard library's urllib module cookielib. (doc currently available for 2.x Version)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With