title: Login to website using python
body: <p>I am trying to login to this <a href="http://friends.cisv.org/index.cfm" rel="noreferrer">page</a> using Python.</p>
  
  <p>I tried using the steps described on this <a href="https://stackoverflow.com/questions/189555/how-to-use-python-to-login-to-a-webpage-and-retrieve-cookies-for-later-usage">other Stack Overflow post</a>, and got the following code:</p>
  
  <pre><code>import urllib, urllib2, cookielib
  
  username = 'username'
  password = 'password'
  
  cj = cookielib.CookieJar()
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  login_data = urllib.urlencode({'username' : username, 'j_password' : password})
  opener.open('http://friends.cisv.org/index.cfm', login_data)
  resp = opener.open('http://friends.cisv.org/index.cfm?fuseaction=activities.list')
  print resp.read()
  </code></pre>
  
  <p>but that gave me the following output:</p>
  
  <pre><code>&lt;SCRIPT LANGUAGE="JavaScript"&gt;
      alert('Sorry.  You need to log back in to continue. You will be returned to the home page when you click on OK.');
      document.location.href='index.cfm';
  &lt;/SCRIPT&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>