Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:参数类型为';非类型';不适用于mysql.connector_Python_Mysql - Fatal编程技术网

Python TypeError:参数类型为';非类型';不适用于mysql.connector

Python TypeError:参数类型为';非类型';不适用于mysql.connector,python,mysql,Python,Mysql,我尝试使用这个函数:当用户输入任何用户名时,如果用户名在数据库中,它将打印“标志”,如果不在数据库中或用户不输入任何内容,它将“不在这里打印”, 因此,当我运行这段代码并尝试输入一些datbase中没有的用户名,并尝试将其保留为空白时,我发现了这个错误 def displayResult(self): name = input("> ") self.cursor.execute("SELECT username FROM customer Where username =

我尝试使用这个函数:当用户输入任何用户名时,如果用户名在数据库中,它将打印“标志”,如果不在数据库中或用户不输入任何内容,它将“不在这里打印”, 因此,当我运行这段代码并尝试输入一些datbase中没有的用户名,并尝试将其保留为空白时,我发现了这个错误

def displayResult(self):
    name = input("> ")
    self.cursor.execute("SELECT username FROM customer Where username = '%s' " % name)
    if name in self.cursor.fetchone():
        print("flag")
    elif name not in self.cursor.fetchone():
        print("Not in here.")
    elif name == "" or name == " ":
        print("Input something.")
如何关闭此错误警告


谢谢

在尝试迭代之前,请尝试检查
fetchone
的返回值,例如:

TypeError: argument of type 'NoneType' is not iterable

在尝试迭代之前,请尝试检查
fetchone
的返回值,例如:

TypeError: argument of type 'NoneType' is not iterable

我明白了,谢谢,但我还是不明白,为什么self.cursor.fetchone()值是None?我明白了,谢谢,但我还是不明白,为什么self.cursor.fetchone()值是None?。