adding variables to shelves

732 views Asked by At

I am new to using shelves, I have a client server programme where the user sends the server the username and password to register an account. Then I add them to a shelve, later in the program when the user wants to log in i need to know how to check if their username and password are in the shelve file.

I have tried:

users=shelve.open('users_details')

#Print recieved message.
print ('recieved from client: ',username)

users['Name']=username

print ('recieved from client: ',password)

users['Password']=password

#and when client wants to log in,check if details are in file
if username and password in users:


    message ='logged in'


    data_out=message.encode()

    #Send data out
    connection.send(data_out)

I get the error:

Traceback (most recent call last):

  File "secureserver.py", line 203, in <module>
if username and password in users:
  File "/usr/lib/python2.7/shelve.py", line 110, in __contains__
return key in self.dict
  File "/usr/lib/python2.7/_abcoll.py", line 369, in __contains__
self[key]
  File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in __getitem__
return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
  File "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap
return function(*_args, **_kwargs)
  File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in <lambda>
return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
TypeError: String or Integer object expected for key, unicode found'
0

There are 0 answers