url - Trouble with "Python Requests" username/password login -


i'm attempting write program grabs data password protected gradebook , analyzes me because university's gradebook doesn't automatically calculate averages. using "requests" in order log in website current code, nothing seems happening. i've tried different methods i've found here on stackoverflow have yet find working code. @ me? thanks.


p.s. when manually log website, looks take me sort of "authorization" url short second, forwards me post login home page.


from requests.adapters import httpadapter requests.packages.urllib3.poolmanager import poolmanager import ssl class myadapter(httpadapter):     def init_poolmanager(self, connections, maxsize, block=false):         self.poolmanager = poolmanager(num_pools=connections,                                       maxsize=maxsize,                                        block=block,                                        ssl_version=ssl.protocol_tlsv1)   import requests url = 'http://learn.ou.edu/d2l/m/login' s = requests.session() s.mount('https://', myadapter()) payload = {     'username': 'myusername',     'password': 'mypassword!' } r = s.get(url, auth=('myusername', 'mypassword!')) print r.status_code print r.content 

the form fill in on http://learn.ou.edu/d2l/m/login, form submits http://learn.ou.edu/d2l/lp/auth/login/login.d2l - need simulate submitting form. make sure had same information in there.

stripping down form see:

<form method="post" enctype="application/x-www-form-urlencoded" action="/d2l/lp/auth/login/login.d2l" onsubmit="return false;">   <input type="hidden" name="d2l_referrer" />   <input type="hidden" name="target" value="/d2l/lp/ouhome/loginhome.d2l?ismobile=1" />   <input type="hidden" name="loginpath" value="/d2l/m/login" />   <input type="text" name="username" />   <input type="password" name="password" /> </form> 

which, @abri has pointed out, uses js mess around before submitting. when submit form (without correct username , password) looks though stuff isn't being changed i'd try hitting form in simplest form.

import requests  s = requests.session() payload = {     'd2l_referrer': '',     'target': '/d2l/lp/ouhome/loginhome.d2l?ismobile=1',     'loginpath': '/d2l/m/login',     'username': 'myusername',     'password': 'mypassword!' } r = s.post('http://learn.ou.edu/d2l/lp/auth/login/login.d2l', data=payload) print r.status_code print r.content 

without un/pw can't go further try , see how on.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -