[Tutor] login

Kent Johnson kent37 at tds.net
Sat Mar 15 22:17:35 CET 2008


SwartMumba snake wrote:
> Using the cookie jar is not going to solve my problem. I don't want to 
> use the cookie jar. I just want to send the right request so that I will 
> be sent back the right header, which will contain the information that I 
> want. Apparently I am not sending the right request because the header 
> that I am receieving does not have the "Set-Cookie"s that I want. i.e. I 
> am being recognized as not logged in (non member etc).

How do you normally log on with a browser? There are two common methods
- basic authentication - this is where the browser pops up a window 
where you enter your user name and password. This type of authentication 
is part of the HTTP protocol. It is supported in urllib2 with the 
HTTPBasicAuthHandler.
- forms-based auth - this is where the web site puts up a form. In this 
case you have to post your credentials to the form.

In either case, if you want to make subsequent requests to the site with 
urllib2, as an authenticated user, you should use the CookieJar as I 
showed you. The cookie jar remembers the cookie and subsequent requests 
with the same opener will send the cookie for you. You don't have to be 
concerned with the headers at all.

Kent


More information about the Tutor mailing list