0

(Using Python 2.7, with Mechanize)

Let's say I have a cookie on Twitter, named auth_token and it's Value is: ABC123.

https://i.gyazo.com/de568907c939617c14a874696664aeeb.png

How do tell Mechanize to import this Cookie? I've heard about Cookielib but I am not sure how to use it. I looked it up, but I've no clue how to set this up with Mechanize.

If someone could help me out, that would be awesome! :)

Coto TheArcher
  • 367
  • 3
  • 13

2 Answers2

0
import Cookie
import cookielib
cookiejar =cookielib.LWPCookieJar()

br = mechanize.Browser()
br.set_cookiejar(cookiejar)
cookie = cookielib.Cookie(auth_token='ABC123')
cookiejar.set_cookie(cookie)
Mike Tung
  • 4,735
  • 1
  • 17
  • 24
  • Nope, I got : `Traceback (most recent call last): File "final.py", line 14, in cookie = cookielib.Cookie(auth_token='ABC123') TypeError: __init__() got an unexpected keyword argument 'auth_token'` – Coto TheArcher Sep 06 '16 at 21:56
0

Why not pass it as HTTP headers

br=mechanize.Browser()
br.addheaders = [('Cookie','name=value')]
Anunay
  • 397
  • 2
  • 10