TypeError: a bytes-like object is required, not 'RowProxy'

TypeError: a bytes-like object is required, not 'RowProxy'

我正在尝试在我的 python 网络应用程序中实现日志 in/sign up/log 输出元素。我正在使用烧瓶。我正在使用 bcrypt 对密码进行哈希处理和加盐处理,但一直收到此错误:类型错误:需要类似字节的对象,而不是 'RowProxy'。密码肯定会存储在哈希和盐中。但是不会让用户登录。

@app.route("/searchPage", methods=['POST','GET'])
def loggingin():
    title = "Search"

    #get request form variables
    username = request.form.get('username')
    if db.execute("SELECT username FROM users WHERE username = :username",{"username": username}).rowcount == 0:
        return render_template("login.html", message="invalid username, please try again.")
    hashed_password = db.execute("SELECT username, password FROM users WHERE username = :username",{"username": username}).fetchone()
    if bcrypt.checkpw(request.form.get('password'), hashed_password):
        return render_template("searchPage.html", title=title)
    else:
        return render_template("login.html", message="Incorrect Password.")

我的 html 是:

{% extends "nav.html" %}
{% block body %}
  <main>
    <h1>{{ message }}</h1>
    <h3>Log In </h3>
    <form action="{{ url_for('loggingin') }}" method="POST">
      <div class="form-group">
        <label>Username</label>
        <input class="form-control" type="text" name="username">
      </div>
      <div class="form-group">
        <label>Password</label>
        <input class="form-control" type="password" name="password">
      </div>
      <button class="btn btn-success" type="submit">Log In</button>
    </form>
  </main>

{% endblock %}

db.execute("SELECT username, password FROM users WHERE username = :username",{"username": 用户名}).fetchone()['password']

不同之处在于此行末尾的 ['password']。 @mechanical_meat