On Fri, 2009-02-20 at 19:39 -0800, Devin wrote:
> I have no problem pulling pages using httplib if the pages do not
> require authentication.  But now I want to pull pages only after
> authenticating.  Access is enforced by the contributed auth package.
> 
> import httplib, urllib
> params = urllib.urlencode({'this_is_the_login_form':1,'username':
> 'myuser', 'password': 'test'})
> headers = {"Content-type": "application/x-www-form-urlencoded",
>             "Accept": "text/plain"}
> conn = httplib.HTTPConnection("myserver")
> conn.request("POST", "/login/", params, headers)
> response = conn.getresponse()
> print response.status, response.reason
> 
> As I said, when hitting pages that do not require auth, I am
> successful and get a 200 response code.  But when auth is needed, I
> get 302 for the code and "found" for the status.
> 
> Any insights?

So you need to act like a browser would. Submit the necessary
authentication form variables, save the returned cookie and send it on
subsequent requests.

Not sure how this is related ot the original question in the thread,
though, which was about redirecting what the user's browser retrieves,
not retrieving web pages inside Python scripts.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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