gpt4 book ai didi

带有 SQLITE3 的 Pythons Bottle

转载 作者:太空宇宙 更新时间:2023-11-04 02:56:52 26 4
gpt4 key购买 nike

我一直在尝试练习 Bottle Py。有一个关于制作APP的教程:TODO。

它工作正常。但是如果任务 id 超过 1 个字符,则表示 10 而不是 1,2,3,4,5,6,7,8,9

它显示如下错误。

ProgrammingError('Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.',)

enter image description here

代码是:

@route('/edit/<no:int>', method='GET')
def edit_item(no):

if request.GET.save:
edit = request.GET.task.strip()
status = request.GET.status.strip()

if status == 'open':
status = 1
else:
status = 0

conn = sqlite3.connect('todo.db')
c = conn.cursor()
c.execute("UPDATE todo SET task = ?, status = ? WHERE id LIKE ?", (edit, status, no))
conn.commit()

return '<p>The item number %s was successfully updated</p>' % no
else:
conn = sqlite3.connect('todo.db')
c = conn.cursor()
c.execute("SELECT task FROM todo WHERE id LIKE ?", (str(no)))
cur_data = c.fetchone()

return template('edit_task', old=cur_data, no=no)

回溯:

1.

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/lib/python2.7/dist-packages/bottle.py", line 1737, in wrapper
rv = callback(*a, **ka)
File "todo.py", line 67, in edit_item
c.execute('SELECT task FROM todo WHERE id LIKE ?', no)
ValueError: parameters are of unsupported type

2.

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/lib/python2.7/dist-packages/bottle.py", line 1737, in wrapper
rv = callback(*a, **ka)
File "todo.py", line 67, in edit_item
c.execute('SELECT task FROM todo WHERE id LIKE ?', (no))
ValueError: parameters are of unsupported type

怎么办?

最佳答案

这可能会发生,因为当您执行 (str(no)) 时,execute 函数将解压缩您的第二个参数,外部 () 将不转换元组,如果元组中只有一个元素,则需要执行 (str(no),)

例如,由于它被识别为字符串,它会将 "10" 解压为 ("1", "0")

关于带有 SQLITE3 的 Pythons Bottle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42111292/

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