Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1053771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:18:16+00:00 2026-05-16T17:18:16+00:00

Is this Python script correct? import urllib, urllib2, cookielib username = ‘myuser’ password =

  • 0

Is this Python script correct?


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()

I found this script HERE.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 https://signin.ebay.com/ws/eBayISAPI.dll?SignIn ) and then go to my inbox on my eBay account (the URL is http://my.ebay.com/ws/eBayISAPI.dll?MyEbay&gbh=1) .

So, here are the values that I need to use in this script:

First (Sing-in) URL: https://signin.ebay.com/ws/eBayISAPI.dll?SignIn

Second URL: http://my.ebay.com/ws/eBayISAPI.dll?MyEbay&gbh=1

My login name on eBay: tryinghard

My password on eBay: gettingsomewhere

With all these new values the above script must look this way:


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&gbh=1') 
resp.read()

Is it correct? I am especially suspicious about the login_data = line (the fourth one from bottom), why is it a j_password there instead of just password?

I tried this script with all these values and it didn’t work. Does anybody know why it doesn’t work in my case?

I’ve already 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, 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 “Google App Engine Software Development Kit” that I had downloaded from “Google App Engine”.

Later I was told here 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 (urllib, urllib2, cookielib) are all built-in modules.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:18:17+00:00Added an answer on May 16, 2026 at 5:18 pm

    A simple “view source” on the login page whose URL you give reveals very easily the following detail about it… (just formatting the HTML minimally for readability):

    <span style="display:-moz-inline-stack" class="unl">
      <label for="userid">User ID  </label></span>
    <span><input size="27" maxlength="64" class="txtBxF"
           value="" name="userid" id="userid"></span></div>
    <div><span style="display:-moz-inline-stack" class="unl">
      <label for="pass">Password  </label></span>
    <span><input size="27" maxlength="64" class="txtBxF"
           value="" name="pass" id="pass" type="password"></span>
    

    As you can see at a glance, the names of the crucial input fields are not username and j_password as you’re using, but rather userid and pass. It’s therefore obviously impossible for your code to work as it currently stands.

    Read a bit more of the page and you’ll also see soon after:

    <input type="checkbox" name="keepMeSignInOption" value="1" id="signed_in"></b>
    <span class="pcsm"><label for="signed_in"><b>Keep me signed in for today.</b>
    

    Most likely you’ll have to simulate that checkbox being selected to get cookies that are usable (at least for anything but a fleeting time;-).

    And so on, and so forth, really — the attempt to automate interaction with a page without bothering to read that page’s source to get the actual IDs and names to use strikes me as definitely displaying a very optimistic attitude towards life, the universe, and everything…;-). Incidentally, to simplify such interaction (after perusing the source;-), I’ve found mechanize quite handy (and more robust than trying to hack it just with the standard library, as you are doing).

    Also, before automatic interaction with a site, always check out its robots.txt to make sure you’re not breaking its terms of use — sites can easily identify “robots” (automated interaction) as opposed to “humans”, and retaliate against robots.txt violation by banning, blacklisting, and worse; you don’t really want to run into that;-).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some questions about the performance of this simple python script: import sys,
Hey brilliant minds out there, I'm trying to get this Python script that I
This is the first Python script I've tried to create. I'm reading a xml
I have a python script the runs this code: strpath = sudo svnadmin create
I'm working on a Python script that transforms this: foo bar Into this: [[Component
In my editor (notepad++) in Python script edit mode, a line ## is this
I have a Python script that is running a few ls commands. This script
I tried running a python script: print Hello, World! And I get this error:
I am trying to write a python script that takes record data like this
I am trying to write my very first python script. This was working but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.