gpt4 book ai didi

python - "Error binding parameter 0 - probably unsupported type"使用 Bottle 访问元素时

转载 作者:行者123 更新时间:2023-12-01 03:21:10 25 4
gpt4 key购买 nike

我有以下代码:

from bottle import response, error, get
import json


@get('/db_Data')
def db_Data(db):

db.execute("SELECT id, name, category, location, date, amount FROM inventory")
names = db.fetchall() # Use db.fetchone() to get results one by one
return json.dumps(names)

@get('/db_Item')
def db_Item(db):
db.execute("SELECT id, name, category, location, date, amount FROM inventory WHERE id=?", (id, ))
names = db.fetchall()
return json.dumps(names)

@error(404)
def error_404_handler(e):

return json.dumps({'Error': {'Message': e.status_line, 'Status': e.status_code}})

if __name__ == "__main__":
from bottle import install, run
from wtplugin import WtDbPlugin, WtCorsPlugin

install(WtDbPlugin())
install(WtCorsPlugin())
run(host='localhost', port=8080, reloader=True, debug=True, autojson=False)

当我只想获得一件元素(第二条路线)时,我得到:

InterfaceError: Error binding parameter 0 - probably unsupported type.

第一条路线工作得很好。

最佳答案

第二个处理程序中没有任何 id 值。您需要在路由中捕获它并将其传递给函数:

@get('/db_Item/<id>')
def db_Item(db, id):
...

关于python - "Error binding parameter 0 - probably unsupported type"使用 Bottle 访问元素时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41911608/

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