How do I create a cookie and add it to a CookieJar instance in python? I have all the info for the cookie (name, value, domain, path, etc) and I don\'t want to extract a new co
Looking at cookielib, you get:
try:
from cookielib import Cookie, CookieJar # Python 2
except ImportError:
from http.cookiejar import Cookie, CookieJar # Python 3
cj = CookieJar()
# Cookie(version, name, value, port, port_specified, domain,
# domain_specified, domain_initial_dot, path, path_specified,
# secure, discard, comment, comment_url, rest)
c = Cookie(None, 'asdf', None, '80', '80', 'www.foo.bar',
None, None, '/', None, False, False, 'TestCookie', None, None, None)
cj.set_cookie(c)
print cj
Gives:
]>
There are no real sanity checks for the instantiation parameters. The ports have to be strings, not int.