将数据插入SQLite数据库失败,sqlite3.InterfaceError:绑定参数0时出错-可能是不支持的类型
我已经浏览了很多在这个网站上提出的问题,除非我是一个很密集的人(谁知道呢),否则我认为他们不会完全复制我的问题 首先让我从一些代码片段开始 桌子 插入函数将数据插入SQLite数据库失败,sqlite3.InterfaceError:绑定参数0时出错-可能是不支持的类型,sqlite,python-3.6,Sqlite,Python 3.6,我已经浏览了很多在这个网站上提出的问题,除非我是一个很密集的人(谁知道呢),否则我认为他们不会完全复制我的问题 首先让我从一些代码片段开始 桌子 插入函数 def insert_moves(move): c = dbConn.cursor() statement = '''insert into moves values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)''' try: c.execute(statement,(move[0], s
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.
我尝试过一些事情,比如删除随机百分比符号以防出现问题,或者将神奇宝贝改为口袋妖怪。但我不明白问题是什么。其他很多都是关于人们发送列表或要插入的对象,而不是字符串/int对象,我不认为这是问题所在。有什么突出的地方吗?所以……这肯定是我的错。如果我发布了调用insert的函数,我就会看到它。我想这只是一个星期五的下午,我的脑子很累
print(move)
result, error2 = db.insert_moves(move)
这是写为
print(move)
result, error2 = db.insert_moves(moves)
其中移动被迭代,以便我可以对其进行一些处理。老实说,这完全是我的错。哦,好吧,我想教训是…在insert函数中,如果你得到这个错误,请检查传递的值的类型。老实说,我现在应该已经做了。但我会记到周五下午。什么是
move
?它是在哪里定义的?move
是一个列表,其内容在堆栈跟踪之前打印出来。您的代码对我来说很好。您可以将其简化为:c.execute(statement,move)
@forpas是的,我试图使其正确…但现在我发现了我的问题,这肯定更干净了。我总是忘记这一点,但这是一种优雅的处理方式。谢谢
print(move)
result, error2 = db.insert_moves(moves)