python - Mechanize does not follow redirect after website login -
python - Mechanize does not follow redirect after website login -
i've been having lot of problem getting should simple login script work on particular website. my code work on website (reddit), doesn't work on:
https://eo-sso-idp.eo.esa.int/idp/umsso20/login
after submitting form , printing response, browser seems sit down on page html web broswer "cannot find" despite beingness saved in local html file (copied , pasted console output notepad text file) username , password copied corresponding form fields. not follow redirect should take admin page.
this code:
# create new mechanize browser instance br = mechanize.browser() # set browser options br.set_handle_equiv(true) br.set_handle_redirect(true) br.set_handle_referer(true) br.set_handle_robots(false) br.set_handle_redirect(mechanize.httpredirecthandler) br.set_handle_refresh(mechanize.httprefreshprocessor(), max_time=1) # open login url br.open("https://eo-sso-idp.eo.esa.int/idp/umsso20/admin") link in br.links(): if link.text == "login": br.follow_link(link) # select first form br.select_form(nr=0) # come in username , password br["cn"] = username br["password"] = password # submit form response = br.submit() print response.read()
(the reason why set browser follow link login page rather go straight because page seems generate unique string appended login url)
in add-on mechanize, tried using next code twill:
browser = get_browser() browser.go("https://eo-sso-idp.eo.esa.int/idp/umsso20/admin") browser.follow_link("login") fv("1", "cn", username) fv("1", "password", password) submit("1") showlinks()
but code produces error:
missingschema: invalid url u'/idp/umsso20/login?fn=t2dwam0zyuzlvth5z3dwwgnmzmlkdz09&act=nwndnlzhnnawaeuzbfvgv3fzastlut09&pars=den6szzdy3hsqmtwyjnwmdhjdwrxtw1on2ffsffyk2jvemtxsfczmfrurwtgqjgwowrjvfrsqvzuvlzmednmd0vdm25hsknvwgz1nki0njjwcgfny0zanlfsn2jql3rfutjym3nirwdvbwjgvmo1bmhgnelyv2yyy2l4nmnicwjzevlln2nfynqrtznas2lurzj2utlnpt0ie': no schema supplied. perhaps meant http:///idp/umsso20/login?fn=t2dwam0zyuzlvth5z3dwwgnmzmlkdz09&act=nwndnlzhnnawaeuzbfvgv3fzastlut09&pars=den6szzdy3hsqmtwyjnwmdhjdwrxtw1on2ffsffyk2jvemtxsfczmfrurwtgqjgwowrjvfrsqvzuvlzmednmd0vdm25hsknvwgz1nki0njjwcgfny0zanlfsn2jql3rfutjym3nirwdvbwjgvmo1bmhgnelyv2yyy2l4nmnicwjzevlln2nfynqrtznas2lurzj2utlnpt0ie?
it seems form post method trying send browser not url.
any help much appreciated
python mechanize twill
Comments
Post a Comment