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: Adds cookie support to urllib2.py
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: jhylton Nosy List: bruthasj, jhylton, jjlee, jlgijsbers, moshez, rhettinger
Priority: normal Keywords: patch

Created on 2002-04-24 16:31 by bruthasj, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cookie-urllib2.patch bruthasj, 2002-04-24 16:31 Adds cookie support to urllib2.py
latest.cookie.patch bruthasj, 2002-06-10 18:06 Removes old 'string' stuff.
testcookie.py bruthasj, 2002-06-10 18:10 Tests cookie support in urllib2
Messages (6)
msg39691 - (view) Author: Jeff Pitman (bruthasj) Date: 2002-04-24 16:31
Problem    
   
Whenever urllib2 encounters a complex sequence of redirects   
and authentication schemes it is extremely difficult to   
"inject" Cookie headers to each request.   
   
Solution   
   
Make a small change to AbstractHTTPHandler that will detect on   
a host-by-host basis if there are any stored cookies.  This is   
done by using a Dict that is initialized on import of urllib2.    
Therefore the Dict of Hosts is available throughout multiple   
instances of request objects and multiple urlopens on those   
objects.     
   
Upon detection, it will send the Cookies along with the other   
request headers to the host.  If there isn't any, it just   
skips it.    
   
The next thing is to collect the Cookies when we get the   
"reply" from the host.  All of this is done within   
AbstractHTTPHandler -- no other modifications required.   
  
Test  
  
I can login into http://mantisbt.sf.net/ which requires the  
browser to maintain a set of cookies during the session.  
  
   
Future   
   
* Maybe use external files to store and control storage of   
cookies   
* Better API in Cookie module so we don't have to do the 
string.split hack   
* Better API in urllib2 for Cookies (or just make it 
transparent? or both?) 
   
   
msg39692 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-05-30 18:20
Logged In: YES 
user_id=80475

I think this looks good.

Please resubmit patch using the latest version of 
urllib2.py and using string methods instead of the (about 
to be deprecated) string module.
msg39693 - (view) Author: Moshe Zadka (moshez) (Python triager) Date: 2002-06-11 11:22
Logged In: YES 
user_id=11645

You're giving no control at all to the Python user over
cookies. Additionally, doing it on a per-import
basis is wrong: what if there are two non-co-operating
modules each using urllib2 for their own purposes?. 
I suggest writing a Cookie mixin which people can mixin to
their classes
when they create a manager, which will keep a list of
cookies and so on.

Thanks.
msg39694 - (view) Author: John J Lee (jjlee) Date: 2002-12-09 20:50
Logged In: YES 
user_id=261020

I just noticed the thread on c.l.py about this, rather late... a day
before that thread started (great minds think alike, apparently),
I released the first version of this:

http://wwwsearch.sourceforge.net/ClientCookie

I intend eventually to get it into a fit state for inclusion in Python.
It's certainly not there yet, but it does work, and is integrated
with urllib2.
msg39695 - (view) Author: John J Lee (jjlee) Date: 2004-06-02 22:41
Logged In: YES 
user_id=261020

This should be closed, since it's obsoleted by the new
module cookielib (patch 963318).
msg39696 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-14 11:33
Logged In: YES 
user_id=469548

Closing as outdated.
History
Date User Action Args
2022-04-10 16:05:15adminsetgithub: 36494
2002-04-24 16:31:35bruthasjcreate