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. Advertising

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. Josef Cihal
    Replies:
    0
    Views:
    771
    Josef Cihal
    Sep 5, 2005
  2. Johny
    Replies:
    1
    Views:
    1,239
  3. cgoldberg
    Replies:
    5
    Views:
    2,360
    cgoldberg
    Mar 3, 2009
  4. TYR
    Replies:
    2
    Views:
    1,155
    Miles Kaufmann
    Jun 21, 2009
  5. evilmrhenry
    Replies:
    0
    Views:
    947
    evilmrhenry
    Nov 3, 2010
Loading...

Share This Page