POST request to ASP.NET page using the Python requests module -
i trying submit post request pwreset.seattleu.edu/change.aspx
can change account password on command line. think have set request properly, after reading various other similar questions, response being returned exact same page , password not being changed. valid response should redirect me pwreset.seattleu.edu/change_success.aspx
code
from bs4 import beautifulsoup import requests pwreset_url = "https://pwreset.seattleu.edu/change.aspx" headers = { 'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'user-agent': 'mozilla/5.0 (windows nt 6.1) applewebkit/537.17 (khtml, gecko) chrome/24.0.1312.57 safari/537.17', 'content-type': 'application/x-www-form-urlencoded', 'accept-encoding': 'gzip,deflate,sdch', 'accept-language': 'en-us,en;q=0.8', 'accept-charset': 'iso-8859-1,utf-8;q=0.7,*;q=0.3' } session = requests.session() session.headers.update(headers) form_response = session.get(pwreset_url, headers=headers) soup = beautifulsoup(form_response.content) viewstate = soup.find('input', {'name': "__viewstate"})['value'] viewstategenerator = soup.find('input', {'name': "__viewstategenerator"})['value'] item_request_body = { 'viewstate': viewstate, 'viewstategenerator': viewstategenerator, '__viewstateencrypted': '', 'username': 'my_username', 'oldpassword': 'my_password', 'newpassword': 'new_password', 'confirmpassword': 'new_password', 'dochg': 'change password >>' } response = session.post(url=pwreset_url, headers=headers, data=item_request_body) print(beautifulsoup(response.content))
am doing wrong?
Comments
Post a Comment