处理格式参数失败; Python“元组”不能转换为MySQL类型

我在这里做这段代码,我在这里出错,因为元组不能在mysql中使用?这是为什么?代码中有错误吗?

码:

            def edit():
                manage = Toplevel(update)
                manage.title('Manage')
                #Clearing entry box
                e_i_d.delete(0,END) 

                def edit():
                    #Establishing connection
                    con = mysql.connect(host='^^^.^^', user='nihaalnz',
                                            password='^^^^', database='nihaalnztrying')
                    # Making SQL command
                    sql_command = "UPDATE patient_info set `full_name`=%s ,`ph_no`=%s,`emirate_id`=%s,`email_addr`=%s,`gender`=%s,`DOB`=%s,`nationality`=%s,`blood_grp`=%s,`COVID_test`=%s,`emergency_no`=%s ;"
                    values = e10.get(), e20.get(), e30.get(), e40.get(), g.get(), e_dt.get(), e50.get(),b.get(),co.get() ,e60.get() 
                    c = con.cursor()
                    #Executing and saving SQL command
                    c.execute(sql_command, (values,))
                    c.execute('commit')
                    con.close()    

                #Defining Labels
                l_head = Label(manage, text='Edit',font=Font(size='20'))
                l1 = ttk.Label(manage, text='Name', font=font_text)
                l2 = ttk.Label(manage, text='Phone Number', font=font_text)
                l3 = ttk.Label(manage, text='Emirates ID', font=font_text)
                l4 = ttk.Label(manage, text='Email Address', font=font_text)
                l5 = ttk.Label(manage, text='Nationality', font=font_text)
                l6 = ttk.Label(manage, text='Emergency Contact Number', font=font_text)
                l7 = ttk.Label(manage, text='Gender', font=font_text)
                l8 = ttk.Label(manage, text='Blood Group', font=font_text)
                l9 = ttk.Label(manage, text='Test for COVID-19', font=font_text)
                l10 = ttk.Label(manage, text='DOB', font=font_text)
                l_wa = Label(manage, text='NOTE: Date must be in yyyy-mm-dd format always', font=font_text,fg='red')

                #Defining Entry boxes and button
                e10 = ttk.Entry(manage)
                e20 = ttk.Entry(manage)
                e30 = ttk.Entry(manage)
                e40 = ttk.Entry(manage)
                e50 = ttk.Entry(manage)
                e60 = ttk.Entry(manage)
                e_dt = ttk.Entry(manage)
                b_cls = ttk.Button(manage, text='Close',command=manage.destroy)
                b_db = ttk.Button(manage, text='Update Data',command=edit)

                main = records[0]

                #Defining Dropdowns
                g = StringVar()
                g.set(main[5])
                opt_g = OptionMenu(manage, g, *gen)

                b = StringVar()
                b.set(main[8])
                opt_blo = OptionMenu(manage, b, *bl_gr)

                co = StringVar()
                co.set(main[9])
                opt_cov = OptionMenu(manage, co, *cov)

                #Placing entry boxes on screen
                e10.grid(row=1, column=1, pady=5, ipady=5, padx=5)
                e20.grid(row=1, column=3, pady=5, ipady=5, padx=5)
                e30.grid(row=2, column=1, pady=5, ipady=5, padx=5)
                e40.grid(row=2, column=3, pady=5, ipady=5, padx=5)
                e50.grid(row=3, column=1, pady=6, ipady=5, padx=5)
                e60.grid(row=3, column=3, pady=5, ipady=5, padx=5)

                #Inserting results on to boxes
                for record in records:
                    e10.insert(0,record[1])
                    e20.insert(0,record[2])
                    e30.insert(0,record[3])
                    e40.insert(0,record[4])
                    e50.insert(0,record[7])
                    e60.insert(0,record[10])
                    e_dt.insert(0,record[6])
                # Closing the connection
                con.close()

                #Placing labels and dropdowns on screen
                l_head.grid(row=0, columnspan=5, pady=10, padx=5)
                l1.grid(row=1, column=0, pady=5, ipady=5, padx=5)
                l2.grid(row=1, column=2, pady=5, ipady=5, padx=5)
                l3.grid(row=2, column=0, pady=5, ipady=5, padx=5)
                l4.grid(row=2, column=2, pady=5, ipady=5, padx=5)
                l5.grid(row=3, column=0, pady=5, ipady=5, padx=5)
                l6.grid(row=3, column=2, pady=5, ipady=5, padx=5)
                l7.grid(row=4, column=0, pady=5, ipady=5, padx=5)
                l8.grid(row=4, column=2, pady=5, ipady=5, padx=5)
                l9.grid(row=5, column=0, pady=5, ipady=5, padx=5)
                l10.grid(row=5, column=2, pady=5, ipady=5, padx=5)

                opt_g.grid(row=4, column=1, pady=5, ipadx=10, padx=5)
                opt_blo.grid(row=4, column=3, pady=5, ipadx=10, padx=5)
                opt_cov.grid(row=5, column=1, pady=5, ipadx=10, padx=5)
                e_dt.grid(row=5, column=3, pady=5, ipady=5, padx=5)
                b_db.grid(row=7, columnspan=5, pady=(5,0), ipadx=10, sticky=E+W)
                b_cls.grid(row=8, columnspan=5, pady=(5,0), ipadx=10, sticky=E+W)
                l_wa.grid(row=6, columnspan=5, pady=5, ipady=5, padx=5, sticky=E+W)

错误:

Tkinter回调中的异常 追溯(最近一次通话):   to_mysql中的文件“ C:\ Users \ nihaa \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ conversion.py”,第183行     返回getattr(自己,“ _ {0} _to_mysql”。格式(类型名称))(值) AttributeError:'MySQLConverter'对象没有属性'_tuple_to_mysql'

在处理上述异常期间,发生了另一个异常:

追溯(最近一次通话):   _process_params中的第432行“ C:\ Users \ nihaa \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ cursor.py”     res = [to imysql中的to_mysql(i)]   文件“ C:\ Users \ nihaa \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ cursor.py”,第432行,位于     res = [to imysql中的to_mysql(i)]   文件“ C:\ Users \ nihaa \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ conversion.py”,第186行,位于to_mysql中     “ MySQL类型” .format(type_name)) TypeError:Python'tuple'无法转换为MySQL类型

在处理上述异常期间,发生了另一个异常:

追溯(最近一次通话):   调用中的文件“ C:\ Users \ nihaa \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ tkinter__init __。py”,行1705     返回self.func(* args)   编辑中的文件“ c:\ pyprojects \患者数据条目\ Patient_Information.py”,行125     c.execute(sql_command,(值))   执行中的文件“ C:\ Users \ nihaa \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ cursor.py”,行557     psub = _ParamSubstitutor(self._process_params(params))   _process_params中的第437行“ C:\ Users \ nihaa \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ cursor.py”     “处理格式参数失败;%s”%err) mysql.connector.errors.ProgrammingError:处理格式参数失败; Python“元组”不能转换为MySQL类型

评论
  • et_et
    et_et 回复

    我猜这在这里坏了

    c.execute(sql_command, (values,))
    

    which means that either sql_command or values causes the problem. Either you write a test to check the values for this, or you add a print statement for values. I strongly believe that values has somethere a python tuple where there should not be one.

    我希望这有帮助!