Python 尝试使用带有关键字参数的 .execute() SQLite API 查询时出错

Python error trying to use .execute() SQLite API query With keyword arguments

我正在学习 SQLite 并且一直在尝试创建一个字符串来存储值和检索行,但是我得到一个错误"execute() takes no keyword arguments."这是我引用数据库的方式:

import sqlite3
dbb = sqlite3.connect('finance.db')
db = dbb.cursor()
username = request.form.get("username")

#query database for username
rows = db.execute("SELECT * FROM users WHERE username = :username", \ 
username=username)

更新

我错误地陈述了我的参数。我使用下面接受的答案中提到的 qmarks 符号来引用 table 行

documentation 说:

The sqlite3 module supports two kinds of placeholders: question marks (qmark style) and named placeholders (named style).

Here’s an example of both styles:

# This is the qmark style:
cur.execute("insert into people values (?, ?)", (who, age))

# And this is the named style:
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})

不支持关键字参数。但是,您可以将它们显式转换为字典(或为 execute 编写一个包装器来执行此操作):

db.execute("SELECT ... :username", dict(username = username))