[TriLUG] python, requests and logging into a web page
Greg Brown
gwbrown1 at gmail.com
Sat Feb 1 16:49:20 EST 2014
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
More information about the TriLUG
mailing list