gpt4 book ai didi

python - 错误 : 1210: Incorrect number of arguments executing prepared statement

转载 作者:行者123 更新时间:2023-11-28 18:06:28 25 4
gpt4 key购买 nike

我正在尝试使用 Python 将数据插入 MySQL。

这个错误的原因是什么?

ProgrammingError: 1210: Incorrect number of arguments executing prepared statement

我的 python 代码:

connection = mysql.connector.connect(host='localhost',
database='popsww2017',
user='root',
password='')
records_to_insert = [('---2q7vcZGU', 'Partner-provided', '35', '9s1Pvm0U8Gg8mRavZhVXdg', 'A663893851990558', '1066/2016/HDHT-Pops-Kha Ly', '1467', '0.100598')]
sql_insert_query = "INSERT INTO raw_music (`Video_ID`, `Content_Type`, `Video_Duration`, `Channel_ID`, `Asset_ID`, `Asset_Labels`, `Owned_Views`, `Partner_Revenue`) VALUES ( '%s', '%s' , '%s' , '%s', '%s' , '%s' , '%s' , '%s') "
cursor = connection.cursor(prepared=True)
result = cursor.executemany(sql_insert_query,records_to_insert)
connection.commit()

我的表:

Video_ID    varchar(50) utf8_unicode_ci     
Content_Type varchar(100) utf16_unicode_ci
Video_Duration int(11)
Channel_ID varchar(100) utf8_unicode_ci
Asset_ID varchar(50) utf32_unicode_ci
Asset_Labels varchar(400) utf32_unicode_ci
Owned_Views int(20)
Partner_Revenue float

最佳答案

让它工作的秘诀是在单值元组的末尾添加一个逗号。

示例:

# a tuple
to_insert = ('A value to insert'**,**)

在这种情况下:

records_to_insert = [('---2q7vcZGU', 'Partner-provided', 35, '9s1Pvm0U8Gg8mRavZhVXdg', 'A663893851990558', '1066/2016/HDHT-Pops-Kha Ly', 1467, 0.100598)**,**]

它适用于单值元组。

希望对您有所帮助!

关于python - 错误 : 1210: Incorrect number of arguments executing prepared statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53185081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com