将数据插入SQLite数据库失败,返回sqlite3.接口错误:绑定参数0时出错-可能是不受支持的类型



我已经浏览了很多在这个网站上提出的问题,除非我很密集(谁知道呢(,否则我认为它们不会完全复制我的问题。

首先让我从一些代码片段开始

CREATE TABLE IF NOT EXISTS moves(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
name char(20),
type char(10),
category char(10),
desc char(200),
share char(3),
priority char(5),
damage_dice char(5),
cool_down char(8),
accuracy char(100),
effect char(200),
move_target char(50),
makes_contact char(3),
contest_cat char(10)
)''')

插入功能

def insert_moves(move):
c = dbConn.cursor()
statement = '''insert into moves values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)'''
try:
c.execute(statement,(move[0], str(move[1]), str(move[2]), str(move[3]), str(move[4]),
str(move[5]), str(move[6]), str(move[7]), str(move[8]), str(move[9]), str(move[10]),
str(move[11]), str(move[12]), str(move[13]),))
dbConn.commit()
return True, ''
except Exception as e:
return False, e

现在,让我向您展示堆栈跟踪,作为其中的一部分,您将看到move在传递到datebase函数之前的打印输出。

现在,这是输出

[1, 'Attack Order', 'Bug', 'Physical', 'The user calls out its underlings to pummel the target.', 'Yes', '-', '1d6', '1 Turn', '100', 'Attack Order deals damage and has an increased critical hit ratio of 50 percent', 'Targets a single adjacent Pokemon.', 'No', 'Clever']
Ignoring exception in command update_moves:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/projects/pokebot/gsheet.py", line 59, in update_moves
result, error2 = db.insert_moves(moves)
File "/projects/pokebot/db.py", line 103, in insert_moves
c.execute(statement,(move[0], str(move[1]), str(move[2]), str(move[3]), str(move[4]), str(move[5]), str(move[6]), str(move[7]), str(move[8]), str(move[9]), str(move[10]), str(move[11]), str(move[12]), str(move[13]),))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InterfaceError: Error binding parameter 0 - probably unsupported type.

我尝试过一些事情,比如删除随机百分比标志,以防出现问题,或者将神奇宝贝改为口袋妖怪。但我不知道问题是什么。其他很多都是关于人们发送列表或要插入的对象之类的东西,而不是一些string/int对象,我不认为这是问题所在。有什么特别的吗?

所以。。。这绝对是我的错。如果我发布了调用insert的函数,我会看到的。我想这只是一个星期五的下午,我的大脑很累。

print(move)
result, error2 = db.insert_moves(move)

这是作为写的

print(move)
result, error2 = db.insert_moves(moves)

哪里的动作被迭代,这样我就可以做一些工作了。老实说,这完全是我的错。哦,好吧,我认为教训是……在insert函数上,如果您收到这个错误,请检查传递的值的类型。老实说,我现在应该这么做了。。但我会把它记到周五下午。

最新更新