Debugging cookielib.CookieJar

R

Roy Smith

I've got a unit test suite which instantiates an HTTP client to test
our server. We depend on session cookies. To handle this, I've got:

def setUp(self):
self.cj = cookielib.CookieJar()
self.opener =
urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))

This works fine on one machine, and fails to return any cookies on
another. I can watch the Set-Cookie headers go by in tcpdump and see
that there's no Cookie header in the other direction on the machine
which fails. I can also put:

for cookie in self.cj:
print cookie

into one of my test methods and on the machine where it works, it
prints a cookie and on the machine where it fails, it prints nothing.

I assume there's something subtle going on with hostnames which is
causing the cookie domains to not match. Any suggestions for
debugging this? Is there some way to put CookieJar or
HTTPCookieProcessor into some sort of verbose mode so it logs what
it's doing? I'm looking for the magic switch which makes it print out
"Got cookie X in domain D1, looking for cookies to return for domain
D2, X does not match because D1 != D2".
 
R

Roy Smith

Ah, never mind. I found "cookielib.debug = True", which told me
exactly what I needed to know. I did indeed have a hostname problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top