More than one cookie with urllib2

From: Rafael T. Ugolini (rafael_at_vexbr.com.br)
Date: 12/11/03


Date: Thu, 11 Dec 2003 19:05:43 -0200
To: python-list@python.org

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)

nebula:/home/nebuloso# nc -l -p 80
POST / HTTP/1.0
Host: localhost
User-agent: Python-urllib/2.1
Cookie: JSESSIONID=DFA58D39389BA5E3CEB5C92F9308792C
Content-length: 34
Content-type: application/x-www-form-urlencoded
                                                                                                                                              
j_username=psyca&j_password=******

---
and another thing , headers is a dic , you cant add 2 equal keys...
dunno how to do it.
Thanks.


Relevant Pages

  • Re: EndSession is throwing an error
    ... Here is the XML that I sent from the log; ... Host: localhost ... User-Agent: gSOAP/2.7 ...
    (microsoft.public.data.xmlanalysis)
  • Re: [BUG/PATCH] cgi/session.rb (SOLVED?)
    ... the separator in the Cookie header ... A server SHOULD also accept comma ... some encoding method such as URL style %XX encoding is recommended, ... HTTP_COOKIE post, but they both did at several points during testing (somehow related to browsing from localhost). ...
    (comp.lang.ruby)
  • [Full-disclosure] Browser cookie handling: possible cross-domain cookie sharing
    ... common (I use the trailing dot notation for FQDNs in this mail to keep clear ... the beginning of the hostname visited must in itself be a host or domain ... but also mistakenly for the entire top-level domain ... when the cookie is accepted, ...
    (Full-Disclosure)
  • Re: How to logon and post this to a web form
    ... > to interface with a website. ... > Host: www.betfair.com ... > Connection: Keep-Alive ...
    (microsoft.public.dotnet.languages.vb)
  • Re: IE 5.5 Update Q321232 Issue
    ... >Do you use a non-RFC compliant host name for the intranet ... >and 6.0 in November 2001 to fix a cookie handling ... they updated their code to only allow RFC ...
    (microsoft.public.security)