cookielib
Boris Ozegovic
ninja.krmenadl at nes.com
Fri Aug 10 11:47:30 EDT 2007
Hi
I have HTTP client which accepts cookies. If client allready has cookie,
but that cookie has expired, server sends him new cookie, and in response
object Set-Cookie: header everything is fine, but if I reload request,
client sends expired cookie, and not the new one. In cookiejar there is
only new and valid cookie, and if I use regular browser everything is fine.
The code is following:
urlopen = urllib2.urlopen
Request = urllib2.Request
cj = cookielib.LWPCookieJar()
COOKIEFILE = 'cookies.lwp'
if os.path.isfile(COOKIEFILE):
# if we have a cookie file already saved
# then load the cookies into the Cookie Jar
cj.load(COOKIEFILE)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
url = "http://localhost:8000/files/index.html"
params = {'question':question}
data = urllib.urlencode(params)
Request(url, data)
try:
response = urlopen(Request)
etc.
Only if I create new request object the new cookie is send, but I don't
want to create new object. And idea?
--
Ne dajte da nas lažljivac Bandić truje:
http://cnn.blog.hr/arhiva-2007-06.html#1622776372
More information about the Python-list
mailing list