Logging in to a site using Python Requests -


i trying programmatically log site using python requests library:

login_url='https://login.drexel.edu/cas/login?service=https://one.drexel.edu/c/portal/login'  login_payload = {                                                              'username':'lk12',                                                         'password':'1q2w3e4r5t6y'                                                  }  s = requests.post(login_url, data=login_payload)      print s.text 

note, username , password key retrieved page source's username , password id field.

upon running script , looking @ output of s.text, appears never logged in despite login credentials being valid. output of s.text login page.

using firefox, checked curl request looks like:

curl 'https://login.drexel.edu/cas/login?service=https%3a%2f%2fone.drexel.edu%2fc%2fportal%2flogin' -h 'host: login.drexel.edu' -h 'user-agent: mozilla/5.0 (macintosh; intel mac os x 10.10; rv:35.0) gecko/20100101 firefox/35.0' -h 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -h 'accept-language: en-us,en;q=0.5' --compressed -h 'referer: https://login.drexel.edu/cas/login?service=https%3a%2f%2fone.drexel.edu%2fc%2fportal%2flogin' -h 'cookie: jsessionid=b3dd2f8e144d98090ac63b995d9030ab; idmsessid=lk12' -h 'connection: keep-alive' --data 'username=lk12&password=1q2w3e4r5t6y&lt=lt-745860-ymf7kykd3ssvfeumxpidlwqobbczcq&execution=e2s1&_eventid=submit&submit=connect' 

that request looks python request. not quite sure doing wrong

someone can more, here few things can @ meanwhile:

  1. set user agent actual browser. if don't, it's set "python", , some(many?) websites can have user-agent blocked default. test sending script to: http://whatsmyuseragent.com/

how set user-agent: sending "user-agent" using requests library in python

  1. if plan on keeping login session make other requests, should use session()

python requests , persistent sessions

  1. check html hiddin fields in form. looks there few. , may have send too. looks lt parameter may authentication token.

if that's true, need loging page first, read content, parse page extract token string, , add payload. notice being sent on through browser request. if match values sent, should work. (except taken value dynamically generated on each type request login page).

hidden fields

<input type="hidden" name="lt" value="lt-392592-vzctmdl2wvqcc5webcw9foiijilowz" /> <input type="hidden" name="execution" value="e2s1" /> <input type="hidden" name="_eventid" value="submit" /> 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -