script to Login a website

This is the place for queries that don't fit in any of the other categories.

script to Login a website

Postby wachkama » Wed Jul 31, 2013 2:51 pm

I have created a script to log in a website. It gets its username and password from two files, then log's in with this credentials. My code is not showing me what username it is using to login from the file. And I am not sure if it is even opening up the url and prompting for login. I am stuck can someone help me ?

Code: Select all
import urllib, urllib2

user = open ('users.txt' , 'r')
password = open ('password.txt' , 'r')

for users in user:
    password.seek(0)
    for pass_list in password:
        login_data = users + '\n' + pass_list
        print login_data
       
base_url = 'http://mysite.com'       
#login action we want to post data to 
response = urllib2.Request(base_url)     
login_action = '/auth/login'   
login_action = base_url + login_action
response = urllib2.urlopen(login_action, login_data)
response.read()
print response.headers
print response.getcode()
Last edited by micseydel on Thu Aug 01, 2013 9:37 pm, edited 1 time in total.
Reason: Locked OP.
wachkama
 
Posts: 1
Joined: Mon Jul 29, 2013 6:23 pm

Re: script to Login a website

Postby Kebap » Thu Aug 01, 2013 12:41 pm

Hi wachkama, welcome to the forums!
For this kind of problem, I can absolutely recommend you try out the faboulos debug command that is called "print".
Just print everything and see if it really shows what you would expect it to, and where it starts to go wrong.
Did you open the files correctly, can python actually read them, do you find any users, do you find passwords, etc.
For example, I assume, something may go wrong with your open() and seek(), because I see no read().
Then again, I am no python pro and just guessing, so I myself would also use "print" to confirm my assumption.
Last edited by micseydel on Thu Aug 01, 2013 9:37 pm, edited 1 time in total.
Reason: Removed quote after locking OP. (Thanks though Kebap.)
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 282
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 2 guests