urllib2 OpenerDirector question on usage.

John J. Lee jjlee at reportlab.com
Fri Jun 23 20:32:47 EDT 2006


"Ant" <antroy at gmail.com> writes:

> I am using urllib2 as a part of a web testing tool. One of the things I
> am testing is the effect of two different people perforing the same
> actions on the website - do they interfer with each other or not.
> 
> So to emulate this, I essentially have the following function:
> 
> def get_opener():
>     policy = cookielib.DefaultCookiePolicy(rfc2965=True)
>     cj = cookielib.CookieJar(policy)
>     return urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> 
> Now am I right in thinking that since I am creating a separate
> CookieJar for each opener, then creating two openers and using one for
> each hypothetical user will achieve this effect - i.e. sessions will be
> separate from each other in the app, since the openers will return
> different session cookies back to the server.

Yes.

As far as cookies are concerned, anyway (and assuming you're not
sharing cookies by e.g. loading and saving from a single file,
obviously).  Presumably the two users will also be separate login
users too (i.e. have separate usernames and passwords -- or other
credentials).


John



More information about the Python-list mailing list