title: Using Python and Mechanize to submit form data and authenticate
body: <p>I want to submit login to the website Reddit.com, navigate to a particular area of the page, and submit a comment.  I don't see what's wrong with this code, but it is not working in that no change is reflected on the Reddit site.</p>
  
  <pre><code>import mechanize
  import cookielib
  
  
  def main():
  
  #Browser
  br = mechanize.Browser()
  
  
  # Cookie Jar
  cj = cookielib.LWPCookieJar()
  br.set_cookiejar(cj)
  
  # Browser options
  br.set_handle_equiv(True)
  br.set_handle_gzip(True)
  br.set_handle_redirect(True)
  br.set_handle_referer(True)
  br.set_handle_robots(False)
  
  # Follows refresh 0 but not hangs on refresh &gt; 0
  br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
  
  #Opens the site to be navigated
  r= br.open('http://www.reddit.com')
  html = r.read()
  
  # Select the second (index one) form
  br.select_form(nr=1)
  
  # User credentials
  br.form['user'] = 'DUMMYUSERNAME'
  br.form['passwd'] = 'DUMMYPASSWORD'
  
  # Login
  br.submit()
  
  #Open up comment page
  r= br.open('http://www.reddit.com/r/PoopSandwiches/comments/f47f8/testing/')
  html = r.read()
  
  #Text box is the 8th form on the page (which, I believe, is the text area)
  br.select_form(nr=7)
  
  #Change 'text' value to a testing string
  br.form['text']= "this is an automated test"
  
  #Submit the information  
  br.submit()
  </code></pre>
  
  <p>What's wrong with this?</p>