Multiple cookie headers and urllib2

evilmrhenry evilmrhenry at
Tue Nov 2 23:50:39 CET 2010

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 ="")
print r.readlines()
#Code End 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.

More information about the Python-list mailing list