gpt4 book ai didi

python - 错误 :not all arguments converted during string formatting

转载 作者:行者123 更新时间:2023-11-28 23:28:07 25 4
gpt4 key购买 nike

我有这个注册页面,当我提交表单时出现此错误:并非所有参数都在字符串格式化期间转换

class RegistrationForm(Form):
email = StringField('Email address')
password = PasswordField('password')
name = StringField('Name')

@app.route('/register/', methods=['GET', 'POST'])
def register():
try:
form = RegistrationForm(request.form)
if request.method == 'POST':
email = form.email.data
password = sha256_crypt.encrypt((str(form.password.data)))
con = connection()
cur=con.cursor()
x = cur.execute("SELECT * FROM user WHERE username = (%s)",(thwart(email)))
if int(x) > 0:
return render_template('register.html',form=form)
else:
cur.execute("INSERT INTO user (username,password,name) VALUES (%s,%s,%s);",(thwart(email),thwart(password),thwart(name),))
con.commit()
cur.close()
con.close()
return redirect(url_for('dashboard'))

return render_template('register.html', form=form)
except Exception as e:
return str(e)

最佳答案

x = cur.execute("SELECT * FROM user WHERE username = (%s)",(thwart(email)))

execute 的第二个参数应该是一个元组,你缺少一个 ,:

cur.execute("SELECT * FROM user WHERE username = (%s)",(thwart(email),))

我猜你也不需要 %s 周围的 () 但这取决于你的表的实际外观。

进一步说明:

('str') 将求值为字符串 'str',而不是包含它的元组。

为了创建一个元组,您必须包含一个逗号:('str',)

关于python - 错误 :not all arguments converted during string formatting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38474576/

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