pickle.load not working?

S

sp1d3rx

I have the following code for controlling access:
----------------------
#check login credentials...
def cklogin(ipaddy, user, authcoded):
try:
print "Opening file:", user
f = file(user,'r+') #load in the user from the file
cusr = pickle.load(f)
print "User Authcode:", cusr.authcode
print "Supplied:", authcoded
print "Login:", cusr.login
if cusr.authcode == authcoded:
print "User", user, "successfully logged in."
cusr.loggedin=TRUE
cusr.invalid_logins = 0
cusr.ip = ipaddy
pickle.dump(cusr, f) # save the new status...
del cusr
f.close()
return mkcookie(ipaddy)
else:
print "Invalid login attempt."
del cusr
f.close()
except IOError:
print "User does not exist!"
return FALSE
----------------------
it reads a file saved this way:
----------------------
import pickle

class chatuser: #container for storing user information...
login = ""
authcode = ""
cookie = ""
ip = ""
loggedin = 0
invalid_logins = 0
allow_login = 1
status = ""
realname = ""
phone = ""
email = ""

derek = chatuser
derek.login = "username"
derek.authcode = "password"
derek.cookie = "123456"
derek.ip = "127.0.0.1"
derek.loggedin = 0
derek.invalid_logins = 0
derek.allow_login = 1
derek.status = "here"
derek.realname = "Derek W."
derek.phone = "480-XXX-XXXX"
derek.email = "(e-mail address removed)"
f = file(derek.login, 'w')
pickle.dump(derek, f)
f.close()
 
M

Marc 'BlackJack' Rintsch

In <[email protected]>,
it reads a file saved this way:
----------------------
import pickle

class chatuser: #container for storing user information...
login = ""
authcode = ""
cookie = ""
ip = ""
loggedin = 0
invalid_logins = 0
allow_login = 1
status = ""
realname = ""
phone = ""
email = ""

derek = chatuser

If this is copy and pasted and not just a typo then `derek` is just
another name for the `chatuser` class now and not an *instance* of it.

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top