Skip to content Skip to sidebar Skip to footer

Python: 'nonetype' Object Is Not Subscriptable' Error

I'm new to databases in Python, so to practice some key skills I'm building a login screen that writes usernames and hashed passwords to the database, and then checks the user's in

Solution 1:

Your select Username query is returning no rows. So the result set is empty and there is nothing to fetch. So your fetchone call returns None instead of the row tuple you expect.

Solution 2:

When tyour query return 0 rows fetchone will return None:

usernameSql = """SELECT Username FROM Details WHERE Password = '%s'""" % (passwordAttempt) # Selecting username in database
cur.execute(usernameSql)
usernameSql = cur.fetchone()
# check if the query return at least one recordif usernameSql:
    userFetched = usernameSql[0] 
else:
   # show a error or somthing

Post a Comment for "Python: 'nonetype' Object Is Not Subscriptable' Error"