Fergus Fitzpatrick
Fergus Fitzpatrick

Reputation: 48

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

I am trying to implement a log in/sign up/log out element in my python web app. I am using Flask. I am using bcrypt to hash and salt passwords but keep receiving this error: TypeError: a bytes-like object is required, not 'RowProxy'. passwords are definitely getting stored in a hash and salt. But will not allow users to log in.

@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.")

And my html is:

{% 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 %}

Upvotes: 0

Views: 158

Answers (1)

Fergus Fitzpatrick
Fergus Fitzpatrick

Reputation: 48

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

Differnce was the ['password'] at end of this line. @mechanical_meat

Upvotes: 1

Related Questions