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 record
if usernameSql:
userFetched = usernameSql[0]
else:
# show a error or somthing