1

The login form is as follows:

<form action="/idp/profile/SAML2/Redirect/SSO?execution=e1s1" method="post" name="loginForm">
    <div class="form-element-wrapper">
        <label for="username">Username</label>
        <input autocapitalize="off" autofocus="" class="round" id="username" name="j_username" placeholder="GatorLink Username" type="text" value="">
    </div>
    <div class="form-element-wrapper">
        <label for="password">Password</label>
        <input autocapitalize="off" class="round" id="password" name="j_password" placeholder="Password" type="password" value="">
    </div>
    <div class="form-element-wrapper">
        <input type="hidden" name="donotcache" value="0">
    </div>
    <div class="form-element-wrapper">
        <input id="_shib_idp_revokeConsent" type="hidden" name="_shib_idp_revokeConsent" value="false">
    </div>
    <div class="form-element-wrapper">
        <button class="round" type="submit" name="_eventId_proceed">Login</button>
    </div>
</form>

The simple code is as follows:

import urllib
import urllib2
username = "xxx"
password = "xxx"
url = 'https://login.xxx.edu/idp/profile/SAML2/Redirect/SSO?execution=e1s1'
values = { 'j_username': username,'j_password': password }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
print result

It results in

HTTPError: Bad Request

Is there any other data I should provide to let it login? Can anyone explain it how to do it step by step?

Py Py
  • 11
  • 2
  • 1
    It's a post request right ? See the method="post" in the form. http://stackoverflow.com/questions/6348499/making-a-post-call-instead-of-get-using-urllib2 Also, you can use the requests module which is higher level than urllib. http://docs.python-requests.org/en/master/ – SnoozeTime Jul 07 '16 at 01:49
  • It makes sense. I tried to use post method, but it still doesn't work. – Py Py Jul 07 '16 at 05:22

0 Answers0