[Patches] [ python-Patches-548197 ] Adds cookie support to urllib2.py

noreply@sourceforge.net noreply@sourceforge.net
Thu, 30 May 2002 11:20:19 -0700


Patches item #548197, was opened at 2002-04-24 11:31
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=548197&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Jeff Pitman (bruthasj)
Assigned to: Nobody/Anonymous (nobody)
Summary: Adds cookie support to urllib2.py

Initial Comment:
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?) 
   
   

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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-05-30 13:20

Message:
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.

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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=548197&group_id=5470