Multiple cookie headers and urllib2

Discussion in 'Python' started by evilmrhenry, Nov 2, 2010.

  1. evilmrhenry

    evilmrhenry Guest

    Python 2.6.4 on Ubuntu. I'm not sure if this is a bug or if I'm just
    doing this wrong...

    I'm trying to include two cookies when I use urllib2 to view a page.
    #Code Start
    import urllib2

    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
    opener.addheaders.append(("Cookie", "user=abcd"))
    opener.addheaders.append(("Cookie", "password=12345"))
    print opener.addheaders
    r = opener.open("http://emhsoft.com/docs/cookies.php")
    print r.readlines()
    #Code End

    http://emhsoft.com/docs/cookies.php is live, and just includes
    <?php print_r($_COOKIE); ?>
    The output is
    [('User-agent', 'Python-urllib/2.6'), ('Cookie', 'user=abcd'),
    ('Cookie', 'password=12345')]
    ['Array\n', '(\n', ' [user] => abcd\n', ')\n', ' ']

    I expected both of the cookies to show up, not just one.
     
    evilmrhenry, Nov 2, 2010
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dont bother
    Replies:
    0
    Views:
    1,112
    dont bother
    Mar 3, 2004
  2. =?ISO-8859-1?Q?Eino_M=E4kitalo?=

    urllib2 and Set-Cookie with "302 Moved temporarily"

    =?ISO-8859-1?Q?Eino_M=E4kitalo?=, Dec 13, 2004, in forum: Python
    Replies:
    2
    Views:
    931
    =?ISO-8859-1?Q?Eino_M=E4kitalo?=
    Dec 13, 2004
  3. Josef Cihal
    Replies:
    0
    Views:
    1,288
    Josef Cihal
    Sep 5, 2005
  4. Johny
    Replies:
    1
    Views:
    1,360
  5. cgoldberg
    Replies:
    5
    Views:
    2,586
    cgoldberg
    Mar 3, 2009
  6. TYR
    Replies:
    2
    Views:
    1,410
    Miles Kaufmann
    Jun 21, 2009
  7. Phil
    Replies:
    4
    Views:
    1,026
    Gabriel Genellina
    Jan 17, 2010
  8. Ian
    Replies:
    2
    Views:
    2,805
Loading...