[ python-Bugs-1647037 ] cookielib.CookieJar does not handle cookies when port in url

SourceForge.net noreply at sourceforge.net
Thu Feb 1 01:17:42 CET 2007


Bugs item #1647037, was opened at 2007-01-29 12:31
Message generated for change (Comment added) made by jjlee
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1647037&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: STS (tools-sts)
Assigned to: Nobody/Anonymous (nobody)
Summary: cookielib.CookieJar does not handle cookies when port in url

Initial Comment:
In Python 2.5 the cookielib.CookieJar does not handle cookies (i.e., recognise the Set-Cookie: header) when the port is specified in the URL.

e.g., 
import urllib2, cookielib
cookiejar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
# add proxy to view results
proxy_handler = urllib2.ProxyHandler({'http':'127.0.0.1:8080'})
opener.add_handler(proxy_handler)
# Install opener globally so it can be used with urllib2.
urllib2.install_opener(opener)
# The ':80' will cause the CookieJar to never handle the 
# cookie set by Google
request = urllib2.Request('http://www.google.com.au:80/')
response = opener.open(request)
response = opener.open(request) # No Cookie:
# But this works
request = urllib2.Request('http://www.google.com.au/')
response = opener.open(request)
response = opener.open(request)# Cookie: PREF=ID=d2de0..

----------------------------------------------------------------------

Comment By: John J Lee (jjlee)
Date: 2007-02-01 00:17

Message:
Logged In: YES 
user_id=261020
Originator: NO

This is not a bug.  If you turn on cookielib logging (see below), you'll
see that Google sends back a cookie for google.com (not .com.au) on the
first request iff you add the port number.  That cookie should not be sent
back to the server.  My copy of Firefox 1.5.0.9 doesn't send back a cookie
here either.

(note they do send a .com.au cookie when you do a search, presumably
because the search button lands you at a URL without the :80 on the end. 
It's probably just a minor oversight or an optimisation that they don't
send the .com.au cookie when you include the :80)

To turn on logging:

import sys, logging
logger = logging.getLogger("cookielib")
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.DEBUG)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1647037&group_id=5470


More information about the Python-bugs-list mailing list