TypeError: Python 'method' cannot be converted to a MySQL type

TypeError: Python 'method' cannot be converted to a MySQL type

好吧,让我解释一下发生了什么我正在使用 tkinter 表单并获取正在填写的信息,我正在从包含电影的数据库中选择信息。这段代码我已经写了两次,一次是在没有从 tkinter 表单中获取信息的情况下编写的,然后第二次是在从 tkinter 表单中获取信息的情况下编写的。我不确定错误来自哪里,因为代码没有被更改。
这是正常运行的代码:

def PersonalityQuiz():
QuizUI = tk.Tk()
QuizUI.title("Personality Quiz")
QuizUI.geometry('700x300')

firstname = input("What is your first name?")
surname = input("What is your surname?")

answer1 = q1()
answer2 = q2()
answer3 = q3()
answer4 = q4()
answer5 = q5()

print(answer4,answer5)

sql = "SELECT * FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s AND Sub_Genre = %s ORDER BY imdb desc"
statement = (answer1,answer2,answer3,answer4,answer5)

SQLFilmID = "SELECT FilmID FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s AND Sub_Genre = %s"

mycursor = mydb.cursor()
mycursor.execute(sql,statement)
myresult = mycursor.fetchall()

listbox = tk.Listbox(QuizUI)
listbox.pack()

for i in myresult:
    listbox.insert(tk.END, i)

mycursor.execute(SQLFilmID,statement)
FilmID = mycursor.fetchall()

SQLinsert = "INSERT INTO users (FirstName, Surname) VALUES (%s,%s)"
vals = (firstname,surname)
mycursor.execute(SQLinsert,vals)
mydb.commit()

UserID = mycursor.lastrowid

for i in FilmID:
    LinkInsert = "INSERT INTO userlink (UserID, FilmID) VALUES (%s,%s)"
    vals = (str(UserID), str(i[0]))
    mycursor.execute(LinkInsert, vals)
    mydb.commit()

QuizUI.mainloop()

错误代码如下:

def guiform():
genres = [
    "Action",
    "Adventure",
    "Animation",
    "Comedy",
    "Crime",
    "Documentry",
    "Drama",
    "Family",
    "Fantasy",
    "Horror",
    "Musical",
    "Sci-Fi",
    "Spy",
    "Superhero",
    "War",
] #etc

guitest = tk.Tk()
guitest.geometry("700x400")

frame1 = tk.Frame(master=guitest, height=200, width=100, bg="crimson")
frame1.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)

values = tk.StringVar(guitest)
values.set(genres[0]) # default value

lblfirstname = tk.Label(frame1, text="First Name")
lblfirstname.grid(row=1,column=2)
ENTfirstname = tk.Entry(frame1)
ENTfirstname.grid(row=2,column=2)

lblsurname = tk.Label(frame1, text="Surname")
lblsurname.grid(row=3,column=2)
ENTsurname = tk.Entry(frame1)
ENTsurname.grid(row=4,column=2)

lbl1 = tk.Label(frame1, text="How old are you?")
lbl1.grid(row=1,column=0)
question1 = tk.Entry(frame1)
question1.grid(row=2,column=0)

lbl2 = tk.Label(frame1, text="What is the longest you would want a film to be? (minutes)")
lbl2.grid(row=4,column=0)
question2 = tk.Entry(frame1)
question2.grid(row=5,column=0)

lbl3 = tk.Label(frame1, text="What is the oldest year you would watch a movie from (e.g. 1985)")
lbl3.grid(row=6,column=0)
question3 = tk.Entry(frame1)
question3.grid(row=7,column=0)

lbl4 = tk.Label(frame1, text="What is your preferred Genre?")
lbl4.grid(row=8,column=0)
w = tk.OptionMenu(frame1, values, *genres)
w.grid(row=9, column=0)

submit = tk.Button(frame1, text="Submit information", command=lambda:infoget(question1.get,question2.get(),question3.get(),values.get()),width=18)
submit.grid(column=0, row=10)

listbox=tk.Listbox(frame1)
listbox.grid(row=0,column=1, rowspan=10)

def infoget(answer1,answer2,answer3,answer4):
    sql = "SELECT * FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s ORDER BY imdb desc"
    statement = (answer1,answer2,answer3,answer4)

    mycursor = mydb.cursor()
    mycursor.execute(sql, statement)
    myresult = mycursor.fetchall()

    for i in myresult:
        listbox.insert(tk.END, i)

    SQLFilmID = "SELECT FilmID FROM Movies WHERE PG_Rating <= %s AND Minutes <= %s AND Year >= %s AND Genre = %s ORDER BY imdb desc"
    mycursor.execute(SQLFilmID,statement)
    FilmID = mycursor.fetchall()

    
    SQLinsert = "INSERT INTO users (FirstName, Surname) VALUES (%s,%s)"
    vals = (str(firstname),str(surname))
    mycursor.execute(SQLinsert,vals)
    mydb.commit()

    #Returns the Primary Key of the last row accessed by the SQL cursor
    UserID = mycursor.lastrowid

    for i in FilmID:
        LinkInsert = "INSERT INTO userlink (UserID, FilmID) VALUES (%s,%s)"
        vals = (str(UserID), str(i[0]))
        mycursor.execute(LinkInsert, vals)
        mydb.commit()

    guitest.update

guitest.mainloop()

这是它产生的可爱错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\lupin\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\conversion.py", line 183, in to_mysql
    return getattr(self, "_{0}_to_mysql".format(type_name))(value)
AttributeError: 'MySQLConverter' object has no attribute '_method_to_mysql'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\lupin\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 432, in _process_params
    res = [to_mysql(i) for i in res]
  File "C:\Users\lupin\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 432, in <listcomp>
    res = [to_mysql(i) for i in res]
  File "C:\Users\lupin\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\conversion.py", line 185, in to_mysql
    raise TypeError("Python '{0}' cannot be converted to a "
TypeError: Python 'method' cannot be converted to a MySQL type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\lupin\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
    return self.func(*args)
  File "Z:\My Files\Student My Documents\A Level\Computing\NEA\nea2.py", line 168, in <lambda>
    submit = tk.Button(frame1, text="Submit information", command=lambda:infoget(question1.get,question2.get(),question3.get(),values.get()),width=18)
  File "Z:\My Files\Student My Documents\A Level\Computing\NEA\nea2.py", line 179, in infoget
    mycursor.execute(sql, statement)
  File "C:\Users\lupin\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 557, in execute
    psub = _ParamSubstitutor(self._process_params(params))
  File "C:\Users\lupin\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 436, in _process_params
    raise errors.ProgrammingError(
mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'method' cannot be converted to a MySQL type

我不知道 and/or 是什么导致了这个错误。如果有人可以帮助解决这个问题或指出正确的方向来解决这个问题,我将不胜感激!
谢谢你,卢平

传递的第一个参数是下面一行中的一个函数:

command=lambda:infoget(question1.get,question2.get(),question3.get(),values.get())

应该是:

command=lambda:infoget(question1.get(),question2.get(),question3.get(),values.get())