Sunday, August 18, 2013

Re: How do I create a script to fill in django admin login form and submit?

You were missing a key. The following works on my machine.

K

---


import requests
login_url = "http://192.168.0.21/admin/login/"


client = requests.session()
client.get(login_url)


csrftoken = client.cookies['csrftoken']


login_data = {'username':'jim', 'password':'beam', 'this_is_the_login_form':'1', 'csrfmiddlewaretoken':csrftoken}


r = client.post(login_url, data=login_data)


target_url = "http://192.168.0.21/admin/auth/user/"
t = client.get(target_url)


'Select user to change' in t.text # True

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate