title: Is this webpage-logging-in Python script correct?
body: <p>Is this Python script correct?</p>
  
  <hr>
  
  <pre><code>import urllib, urllib2, cookielib 
  
  username = 'myuser' 
  password = 'mypassword' 
  
  cj = cookielib.CookieJar() 
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
  login_data = urllib.urlencode({'username' : username, 'j_password' : password}) 
  opener.open('http://www.example.com/login.php', login_data) 
  resp = opener.open('http://www.example.com/hiddenpage.php') 
  resp.read()
  </code></pre>
  
  <hr>
  
  <p>I found this script <strong><a href="https://stackoverflow.com/questions/189555/how-to-use-python-to-login-to-a-webpage-and-retrieve-cookies-for-later-usage">HERE</a></strong>.It is meant to login to a webpage first, retrieve the cookies, store them and use them in order to open some other page in the same website. I want to login in this way to my eBay account (the URL is <a href="https://signin.ebay.com/ws/eBayISAPI.dll?SignIn" rel="nofollow noreferrer">https://signin.ebay.com/ws/eBayISAPI.dll?SignIn</a> ) and then go to my inbox on my eBay account (the URL is <a href="http://my.ebay.com/ws/eBayISAPI.dll?MyEbay&amp;gbh=1" rel="nofollow noreferrer">http://my.ebay.com/ws/eBayISAPI.dll?MyEbay&amp;gbh=1</a>) . </p>
  
  <p>So, here are the values that I need to use in this script:</p>
  
  <p>First (Sing-in) URL: <a href="https://signin.ebay.com/ws/eBayISAPI.dll?SignIn" rel="nofollow noreferrer">https://signin.ebay.com/ws/eBayISAPI.dll?SignIn</a></p>
  
  <p>Second URL: <a href="http://my.ebay.com/ws/eBayISAPI.dll?MyEbay&amp;gbh=1" rel="nofollow noreferrer">http://my.ebay.com/ws/eBayISAPI.dll?MyEbay&amp;gbh=1</a></p>
  
  <p>My login name on eBay: <strong><code>tryinghard</code></strong></p>
  
  <p>My password on eBay: <strong><code>gettingsomewhere</code></strong></p>
  
  <p>With all these new values the above script must look this way:</p>
  
  <hr>
  
  <pre><code>import urllib, urllib2, cookielib 
  
  username = 'tryinghard' 
  password = 'gettingsomewhere' 
  
  cj = cookielib.CookieJar() 
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
  login_data = urllib.urlencode({'username' : username, 'j_password' : password}) 
  opener.open(https://signin.ebay.com/ws/eBayISAPI.dll?SignIn', login_data) 
  resp = opener.open(http://my.ebay.com/ws/eBayISAPI.dll?MyEbay&amp;gbh=1') 
  resp.read()
  </code></pre>
  
  <hr>
  
  <p>Is it correct? I am especially suspicious about the <strong><em><code>login_data =</code></em></strong> line (the fourth one from bottom), why is it a <strong><em><code>j_password</code></em></strong> there instead of just <strong><em><code>password</code></em></strong>?</p>
  
  <p>I tried this script with all these values and it didn't work. Does anybody know why it doesn't work in my case?</p>
  
  <p>I've already <a href="https://stackoverflow.com/questions/2688408/how-can-i-put-all-twill-commands-together-into-one-piece-of-code-in-a-py-file"><strong>learned how to log in to my eBay account and then check some other pages there by means of running a python script that is using twill as an external module</strong></a>, but that was only successful when I ran that script from the command prompt or from the Python shell. It wasn't successful when I tried running that script by means of <a href="http://code.google.com/intl/en/appengine/downloads.html" rel="nofollow noreferrer"><strong>"Google App Engine Software Development Kit"</strong></a> that I had downloaded from <strong><a href="http://code.google.com/intl/en/appengine/docs/whatisgoogleappengine.html" rel="nofollow noreferrer">"Google App Engine"</a></strong>.</p>
  
  <p>Later I was told <strong><a href="https://stackoverflow.com/questions/3621432/using-twill-from-python-to-open-a-link-module-object-has-no-attribute-popen">here</a></strong> that it wasn't successful because "Google App Engine" doesn't like external modules. That's why I found this script - those modules that it is importing in the very beginning (<strong><em>urllib</em></strong>, <strong><em>urllib2</em></strong>, <strong><em>cookielib</em></strong>) are all built-in modules. </p>