You might add:
r = cur.fetchone ()
if not r:
print ('Login failed')
continue
login2, = r
....
Same for the second fetch.
题
Ok, so here i'm basically trying to make a login option to my program, where it querys the database to see if the data is correct. It works fine until I introduce a login that's not in the database. Is there anyway I can make the while working even after the cur.fetchone() gives the error for not fecthing anything?
login= False
print "*.*.*.*.*.*.*LOGIN*.*.*.*.*.*.*"
while login == False:
login1=input("Id:")
login1pw=raw_input("Password:")
cur.execute("select id_func from func where (id_func = %s and function = 'admin');", (login1,))
login2, = cur.fetchone()
cur.execute("select pw from func where id_func = %s", (login1,))
login2pw, = cur.fetchone()
if (login1 == login2 and login1pw == login2pw):
login = True
print "Login successful"
I get this error:
TypeError: 'NoneType' object is not iterable
Thanks in advance!
解决方案
You might add:
r = cur.fetchone ()
if not r:
print ('Login failed')
continue
login2, = r
....
Same for the second fetch.