Multiple cookie headers and urllib2

E

evilmrhenry

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top