title: Mechanize does not follow redirect after website login
body: <p>I've been having a lot of trouble getting what should be a fairly simple login script to work on a particular website. <strong>My code does work on another website (Reddit)</strong>, but it doesn't work on:</p>
  
  <p><a href="https://eo-sso-idp.eo.esa.int/idp/umsso20/login" rel="nofollow">https://eo-sso-idp.eo.esa.int/idp/umsso20/login</a></p>
  
  <p>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.</p>
  
  <p>This is my code:</p>
  
  <pre><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()
  </code></pre>
  
  <p>(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)</p>
  
  <p>In addition to mechanize, I tried using the following code with twill:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>But this code produces the error:</p>
  
  <pre><code>MissingSchema: Invalid URL u'/idp/umsso20/login?fn=T2dWam0zYUZLVTh5Z3dwWGNMZmlKdz09&amp;act=NWNDNlZhNnAwaEUzbFVGV3FZaStLUT09&amp;pars=dEN6SzZDY3hsQmtWYjNWMDhjdWRXTW1ON2FFSFFYK2JvemtXSFczMFRuRWtGQjgwOWRjVFRsQVZUVlZMeDNmd0VDM25hSkNvWGZ1NkI0NjJWcGFNY0ZaNlFSN2JqL3RFUTJYM3NIRWdvbWJGVmo1bmhGNElYV2YyY2l4NmNIcWJZeVlLN2NFYnQrTzNaS2luRzJ2UTlnPT0ie': No schema supplied. Perhaps you meant http:///idp/umsso20/login?fn=T2dWam0zYUZLVTh5Z3dwWGNMZmlKdz09&amp;act=NWNDNlZhNnAwaEUzbFVGV3FZaStLUT09&amp;pars=dEN6SzZDY3hsQmtWYjNWMDhjdWRXTW1ON2FFSFFYK2JvemtXSFczMFRuRWtGQjgwOWRjVFRsQVZUVlZMeDNmd0VDM25hSkNvWGZ1NkI0NjJWcGFNY0ZaNlFSN2JqL3RFUTJYM3NIRWdvbWJGVmo1bmhGNElYV2YyY2l4NmNIcWJZeVlLN2NFYnQrTzNaS2luRzJ2UTlnPT0ie?
  </code></pre>
  
  <p><strong>It seems like the form POST method is trying to send the browser to something that is not actually a URL.</strong></p>
  
  <p>Any help would be much appreciated</p>