On 14 Dec 12:07, Malcolm Tredinnick wrote:
> 
> 
> On Sat, 2008-12-13 at 14:44 -0800, Adrián Ribao wrote:
> > Hello, I'm writing a script and I'd like to login into a django webapp
> > using pycurl or urllib.
> > I've problems with the cookies, and every time the message is: "The
> > session has expired"
> > 
> > Does anybody know how can I make it?
> 
> You forgot to provide an example of what you are doing at the moment, so
> it's a little tricky to work out what needs correcting. I'll make some
> guesses:
> 
> (1) Are you remembering to include all the form fields? In particular,
> that message will be triggered if you leave out the hidden field in the
> form ("this_is_the_login_form=1").
> 
> (2) Are you remembering to track cookie value updates? Once you log in
> -- whenever you change from an anonymous session to an authenticated one
> -- Django changes the value of the cookie. That is, your session id
> changes. So the cookie value that is sent when you first receive the
> login form is not the same as the value that needs to be sent after
> login.
> 
> All that being said, I use curl quite a bit to test interactions with
> Django. My login line generally looks like:
> 
>         curl -c cookies.txt -b cookies.txt -L -d @login-form.txt 
> http://localhost:8000/admin/
>         
> where login-form.txt contains something like
> 
>         username=malcolm&password=secret&this_is_the_login_form=1
>         
> I have a few other files for other common actions, too, and generally
> shell script my way around the admin site and other things I am
> developing in that fashion if I need to check that things haven't
> changed when I'm only intended to make internal changes.

I'd recommend using the Browser class of python mechanize:
    http://wwwsearch.sourceforge.net/mechanize/

Should make most operations a lot easier, plus you can check for links
etc, then just "click" on them which is rather handy.

I'm using it to monitor a few sites (not, unfortunately, written in
django), and it is rather nice being able to just click round the place
and get data out again when needed. Mechanize + BeautifulSoup is
a very nice combination indeed.

Thanks,
-- 
Brett Parker

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to