1

I have exported cookies from Chrome using cookies.txt Chrome plugin. I can easily replay the request using curl with the cookies exported. Some code like curl -b mycookie.txt -c mycookie.txt $url works perfectly.

However, when I was trying to load the session from mycookie.txt using requests, it can't work. After long time debugging, I fond out that requests will not send session cookies(whose expire values is 0 in cookies file) even though I already loaded the expired cookie with following code:

cj = cookielib.MozillaCookieJar('mycookie.txt')
cj.load(ignore_discard=True, ignore_expires=True)
print cj  #it shows the session cookie already loaded

s = requests.Session()
s.cookies = cj
r = s.get(url, headers=myheaders, timeout=10, allow_redirects=False)
print r.request.headers   #this clearly shows the request didn't send the session cookie

How can I make it work?

dezhi
  • 809
  • 8
  • 10

0 Answers0