More than one cookie with urllib2
John J. Lee
jjl at pobox.com
Thu Dec 11 18:09:49 EST 2003
"Rafael T. Ugolini" <rafael at vexbr.com.br> writes:
> Im trying to add more than one cookie with urllib2 but im not getting
> much sucess.
> An example...
>
>
> >>> req =
> urllib2.Request('http://localhost','j_username=psyca&j_password=******',{
> 'Cookie':'sab=contextUrl+https%3A%2F%2Fwwws.vexbr.com.br%2Fcafedev%2F%7CnasIp+10.50.0.3%7CneedCheckCode+false%7ClocationId+85%7CautoLogout+false%7CserviceProviderId+1%7CorigUrl+%2Findex.html%7CwebContext+cafedev%7CclientIp+192.168.1.107%7CnasId+vex_cafedev%7CloginType+0%7Cclass+class+com.wificom.sab.aaa.dto.SessionDTO%7CloginResumed+false%7CloggedIn+false%7Clanguage+en%7CpricingPlanId+0%7CsslPort+443%7CroamingPriceId+0%7CclientMac+00%3A07%3A95%3AD3%3A0C%3A7C%7CserverUrl+https%3A%2F%2Fwwws.vexbr.com.br%2F',
> 'Cookie':'JSESSIONID=DFA58D39389BA5E3CEB5C92F9308792C',
> 'Content-type':'application/x-www-form-urlencoded',
> 'Content-length':str(len('j_username=psyca&j_password=******'))})
> >>> urllib2.urlopen(req)
[...]
Blech.
> and another thing , headers is a dic , you cant add 2 equal keys...
> dunno how to do it.
[...]
If you want to stay sane, use this:
http://wwwsearch.sourceforge.net/ClientCookie
just say:
ClientCookie.urlopen(req)
and forget about cookies. If you insist on doing it by hand, though:
you need to join your key=value pairs with semicolons:
Cookie: foo=bar; spam=eggs
John
More information about the Python-list
mailing list