“使用瓶子访问项目时,错误绑定参数0 - 可能是不支持的类型”

时间:2017-01-28 15:40:02

标签: python sqlite bottle

我有以下代码:

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.

第一条路线运转正常。

1 个答案:

答案 0 :(得分:2)

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

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