You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python执行SQL语句时为何报错ValueError: parameters are of unsupported type?

错误原因及解决办法

错误原因

  1. 参数类型不支持:执行UPDATE语句时,你传入的参数是集合{el, email, password},但Python的sqlite3模块仅支持元组、列表或字典作为参数传递,集合不属于合法参数类型,直接触发ValueError。
  2. UPDATE语句逻辑缺陷:当前语句没有WHERE子句,会修改表中所有行的type、email、password字段,不符合你只更新对应type行的需求。

解决办法

1. 修正参数类型

将集合参数改为元组(多个元素直接用括号包裹即可),示例:

c.execute("UPDATE accounts SET type = ?, email = ?, password = ? WHERE type = ?;", (el, email, password, el))

2. 添加WHERE子句限定更新范围

根据查询逻辑,加上WHERE type = ?来指定仅更新匹配type的行,同时补充对应的参数。

3. 优化数据库连接管理(可选但推荐)

使用with上下文管理器自动管理连接和游标,避免手动操作的遗漏问题:

async def add(ctx, el: str, email: str, password: str):
    with sqlite3.connect("db.sqlite") as con:
        c = con.cursor()
        c.execute("SELECT type FROM accounts WHERE type=?", (el,))
        results = c.fetchall()
        if len(results) == 0:
            await ctx.send("there is no type with this")
        else:
            c.execute("UPDATE accounts SET type = ?, email = ?, password = ? WHERE type = ?;", (el, email, password, el))
            print("done")
            await ctx.send("done")
        # with块结束时会自动提交,无需手动调用con.commit()

内容的提问来源于stack exchange,提问作者signalmute

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 03:45:55