[TriLUG] python, requests and logging into a web page

David Brain dbrain at gmail.com
Sat Feb 1 17:12:34 EST 2014


Hi,

Looks reasonable,  but web scripting easily gets tripped up with
cookies/redirects etc.

Might be worth looking at Mechanize
http://wwwsearch.sourceforge.net/mechanize/ .  That can shield you from a
lot of the complexities.

David
On Feb 1, 2014 4:49 PM, "Greg Brown" <gwbrown1 at gmail.com> wrote:

> All:
>
> I'm trying to use Python to test availability of an external web
> application and I'm getting stuck.  My credentials are working because I
> can use the same to log in via a webpage.  However when I try to log in via
> the python script I see to get stopped at a proxy that lies between the
> front page of the application and the application itself.  I tried to use
> cookies via sessions but that didn't seem to do the trick.  Here is the
> code, fairly redacted because I can't send out my username and password
> obviously.  From a basic structure standpoint can you see anything
> obviously wrong?
>
> Many Thanks!
>
> Greg
>
> import requests
>
> build a session for the cookies
> # create a session
> session = requests.Session()
> session.get('*url_of_cookie_webpage*')
>
>
> # Fill in your details here to be posted to the login form.
> payload = {
>     'inUserName': 'myusername',
>     'inUserPass': 'myPassword'
> }
>
> r = session.post('*url_I'm-trying-to-go*', params=payload,
> allow_redirects=True)
>
> print r.status_code
> print r.text
> --
> This message was sent to: dbrain at gmail.com <dbrain at gmail.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web  :
> http://www.trilug.org/mailman/options/trilug/dbrain%40gmail.com
> Welcome to TriLUG: http://trilug.org/welcome
>


More information about the TriLUG mailing list