Reputation: 73
I've been having a lot of trouble getting what should be a fairly simple login script to work on a particular website. My code does work on another website (Reddit), but it doesn't work on:
https://eo-sso-idp.eo.esa.int/idp/umsso20/login
After submitting the form and printing the response, the browser seems to sit on a page with HTML that my web broswer "cannot find" despite being saved in a local HTML file (copied and pasted from the console output into a notepad text file) with the username and password copied into the corresponding form fields. It does not follow the redirect that should take it to the admin page.
This is my code:
# Create a 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 the login URL
br.open("https://eo-sso-idp.eo.esa.int/idp/umsso20/admin")
for link in br.links():
if link.text == "Login":
br.follow_link(link)
# Select the first form
br.select_form(nr=0)
# Enter the username and password
br["cn"] = username
br["password"] = password
# Submit the form
response = br.submit()
print response.read()
(The reason why I set the browser to follow a link to the login page rather than go to it directly is because the page seems to generate a unique string that is appended to the login URL)
In addition to mechanize, I tried using the following code with 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 this code produces the error:
MissingSchema: Invalid URL u'/idp/umsso20/login?fn=T2dWam0zYUZLVTh5Z3dwWGNMZmlKdz09&act=NWNDNlZhNnAwaEUzbFVGV3FZaStLUT09&pars=dEN6SzZDY3hsQmtWYjNWMDhjdWRXTW1ON2FFSFFYK2JvemtXSFczMFRuRWtGQjgwOWRjVFRsQVZUVlZMeDNmd0VDM25hSkNvWGZ1NkI0NjJWcGFNY0ZaNlFSN2JqL3RFUTJYM3NIRWdvbWJGVmo1bmhGNElYV2YyY2l4NmNIcWJZeVlLN2NFYnQrTzNaS2luRzJ2UTlnPT0ie': No schema supplied. Perhaps you meant http:///idp/umsso20/login?fn=T2dWam0zYUZLVTh5Z3dwWGNMZmlKdz09&act=NWNDNlZhNnAwaEUzbFVGV3FZaStLUT09&pars=dEN6SzZDY3hsQmtWYjNWMDhjdWRXTW1ON2FFSFFYK2JvemtXSFczMFRuRWtGQjgwOWRjVFRsQVZUVlZMeDNmd0VDM25hSkNvWGZ1NkI0NjJWcGFNY0ZaNlFSN2JqL3RFUTJYM3NIRWdvbWJGVmo1bmhGNElYV2YyY2l4NmNIcWJZeVlLN2NFYnQrTzNaS2luRzJ2UTlnPT0ie?
It seems like the form POST method is trying to send the browser to something that is not actually a URL.
Any help would be much appreciated
Upvotes: 1
Views: 1565