This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cookielib.CookieJar does not handle cookies when port in url
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jjlee, tools-sts
Priority: normal Keywords:

Created on 2007-01-29 12:31 by tools-sts, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg31126 - (view) Author: STS (tools-sts) Date: 2007-01-29 12:31
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..
msg31127 - (view) Author: John J Lee (jjlee) Date: 2007-02-01 00:17
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)
msg31128 - (view) Author: STS (tools-sts) Date: 2007-02-01 12:10
You're right! I will close this now...Sorry about that. Also, thanks for the logging/DEBUG code this will be very useful going forward.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44517
2007-01-29 12:31:16tools-stscreate