TypeError:'NoneType'对象没有属性'__getitem__'tkinter错误

时间:2017-05-03 04:51:44

标签: python mysql tkinter

我在这里遇到的问题是,每当我尝试将数据输入到我的用户名输入框(self.KUEntry.get())并在我的查询中运行该框中的输入时,它将返回none并抛出错误中列出的错误问题

该函数应该检查已注册用户的存储salt和hash,并将其与输入框中输入的密码进行比较。

def login_verification(self):

    username = self.KUEntry.get()
    print username

    cursor1.execute = ("SELECT salt FROM User WHERE username = (%s)", username)
    salty = cursor1.fetchone() [0]
    print salty

    cursor2.execute = ("SELECT PashHash FROM User WHERE username = %s", (username))
    hashy = cursor2.fetchone() [0]
    print hashy

    test = hashlib.sha512(username + salty).hexdigest
    print test

    if test == hashy:
        self.mainscreen
    else:
        print "incorrect password"

1 个答案:

答案 0 :(得分:0)

像这样放置我的代码修复了回溯错误,但它没有返回预期的内容。而不是我的cursor1.fetchone和cursor2.fetchone方法返回查询结果,而是返回" none"。

def login_verification(self):

    username = self.KUEntry.get()
    print username

    cursor1.execute = ("SELECT salt FROM User WHERE username = %s", str(username))
    salty = str(cursor1.fetchone())
    print salty

    cursor2.execute = ("SELECT PashHash FROM User WHERE username = %s", str(username))
    hashy = str(cursor2.fetchone())
    print hashy

    test = hashlib.sha512(username + str(salty)).hexdigest
    print test

    if test == hashy:
        self.mainscreen
    else:
        print "incorrect password"