简体   繁体   English

无法处理参数:int(1),它必须是 list、tuple 或 dict 类型

[英]Could not process parameters: int(1), it must be of type list, tuple or dict

I am currently trying to insert two numbers into a column called konto_type_kode from a table called kontotype but i keep getting this error, here is what my code looks like:我目前正在尝试从名为 kontotype 的表中将两个数字插入名为 konto_type_kode 的列中,但我不断收到此错误,这是我的代码的样子:

import createdb
import createtables
import mysql.connector

config = mysql.connector.connect(
    host =  "localhost",
    user = "root",
    password = "root",
    database = "dbank_banksystem"
)

cursor = config.cursor()

addtype1 = """ INSERT INTO kontotype (konto_type_kode) VALUES (%i, %i)"""
addtype1val = (1,2)

cursor.executemany(addtype1,addtype1val)

config.commit()

Placeholders in mysql-connector are %s , not %i . mysql-connector 中的占位符是%s ,而不是%i

cursor.executemany() requires the parameters to be a 2-dimensional sequence, a sequence of rows to add. cursor.executemany()要求参数是二维序列,即要添加的行序列。 So change addtype1val to be a tuple of tuples.所以将addtype1val更改为元组的元组。

You should only have one placeholder in the VALUES list, since you're only inserting into one column.您应该在VALUES列表中只有一个占位符,因为您只插入一列。 cursor.executemany() will repeat the VALUES list enough times for each row. cursor.executemany()将为每一行重复VALUES列表足够的次数。

addtype1val = ((1,), (2,))

addtype1 = """ INSERT INTO kontotype (konto_type_kode) VALUES (%s)"""
addtype1val = (1,2)

cursor.executemany(addtype1,addtype1val)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法处理参数:str(https://help.twitter.com/using-twitter/twitter-supported-browsers),它必须是列表、元组或字典类型 - Could not process parameters: str(https://help.twitter.com/using-twitter/twitter-supported-browsers), it must be of type list, tuple or dict 类型错误:返回类型必须是字符串、字典、元组、响应实例或可调用的 WSGI,但它是一个列表 - Type Error: The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a list 类型错误:视图 function 未返回有效响应。 返回类型必须是字符串、字典、元组、Response 实例,但它是一个 int - TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, but it was a int python中的oracle查询-返回类型必须是字符串、字典、元组 - oracle query in python - The return type must be a string, dict, tuple TypeError:值必须是列表,元组,范围或生成器或dict - TypeError: Value must be a list, tuple, range or generator, or a dict 查看 function 未返回有效响应。 返回类型必须是字符串、字典、元组、响应实例或 WSGI 可调用,但它是一个列表 - view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a list 如何询问打字参数(列表、元组、字典...) - How to interrogate Typing parameters (List, Tuple, Dict...) ValueError: SQL 查询参数应该是元组、列表或字典 - ValueError: SQL query parameters should be a tuple, list or dict 要列出或听写的元组的元组 - Tuple of tuples to list or dict 对字典进行排序但得到“List Indices必须是int,而不是tuple”错误 - Sorting a dictionary but got “List Indices must be int, not tuple” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM