I am trying to get past the authentication challenges for a particular API service using Python Requests. I have already tried BasicHTTP and other default auth methods. So I am trying to send in the username and password via form data.
Here is what Chrome DevTools reveals when I succesfully login manually (let me know if you need more data from DevTools):
Request Method:POST
Status Code:302 Found
Form Data
__LASTFOCUS:
__EVENTTARGET:
__EVENTARGUMENT:
__VIEWSTATE: <hashed stuff>
__VIEWSTATEGENERATOR:7A06DDCB
__SCROLLPOSITIONX:0
__SCROLLPOSITIONY:0
ctl00%24MainContentPlaceHolder%24MainLogin%24UserName:<usernamecleartext>
ctl00%24MainContentPlaceHolder%24MainLogin%24Password:<passwordcleartext>
ctl00%24MainContentPlaceHolder%24MainLogin%24RememberMe:on
ctl00%24MainContentPlaceHolder%24MainLogin%24LoginButton:Log+In+%3E
Here is my code:
import requests
url='<theloginurl>'
payload = {
'ctl00$MainContentPlaceHolder$MainLogin$UserName':'<usernamecleartext>',
'ctl00$MainContentPlaceHolder$MainLogin$Password':'<passwordcleartext>'
}
r = requests.post(url, data=payload)
print(r.url)
print(r)
print(r.headers)
And even if I include the other two form items DevTools reports in my payload dictionary, the result is the same.