1 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊
調(diào)用cursor.execute應(yīng)該在with塊內(nèi),因?yàn)閏ursor僅存在于該塊內(nèi)。
這實(shí)際上是一個(gè)缺失的縮進(jìn):
def log_request(req: 'flask_request', res: str) -> None:
with UseDatabase(app.config['dbconfig']) as cursor:
_SQL = """insert into log
(phrase, letters, ip, browser_string, results)
values
(%s, %s, %s, %s, %s)"""
cursor.execute(_SQL, (req.form['phrase'],
req.form['letters'],
req.remote_addr,
req.user_agent.browser,
res, ))
添加回答
舉報(bào)