I finished doing finance and tested it without many errors i would say. Fun fact, i was implementing a change password and it got me this error
TypeError: a bytes-like object is required, not 'NoneType'
@app.route("/change_password", methods=["GET", "POST"])
@login_required
def change_password():
if request.method == "POST":
# Get info from fields
old_pw = request.form.get("old_password")
new_pw = request.form.get("new_password")
confirm_password = request.form.get("confirm_password")
# Ensure fields are not empty
if not (old_pw or new_pw or confirm_password):
return apology("Field missing", 403)
# Check that both new password are correctly spell
elif not confirm_password == new_pw:
return apology("passwords must be equal", 403)
# Ensure old and new password are different
elif new_pw == old_pw:
return apology("New password cannot be the same", 403)
# Query db for password
rows = db.execute("SELECT hash FROM users WHERE id = :user_id", user_id=session["user_id"])
# Check password is correct
if len(rows) != 1 or not check_password_hash(rows[0]["hash"], old_pw):
return apology("Invalid password", 403)
# Query db to update password
db.execute("UPDATE users SET hash = :password WHERE id = :user_id",
password=generate_password_hash(new_pw), user_id=session["user_id"])
flash("Password Changed Successfully")
return redirect("/")
else:
return render_template("change_pw.html")
this is the log
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.7/site-packages/werkzeug/middleware/proxy_fix.py", line 232, in __call__
return self.app(environ, start_response)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ubuntu/cs50/set8/finance/helpers.py", line 34, in decorated_function
return f(*args, **kwargs)
File "/home/ubuntu/cs50/set8/finance/application.py", line 206, in change_password
if len(rows) != 1 or not check_password_hash(rows[0]["hash"], request.form.get("old_password")):
File "/usr/local/lib/python3.7/site-packages/werkzeug/security.py", line 221, in check_password_hash
return safe_str_cmp(_hash_internal(method, salt, password)[0], hashval)
File "/usr/local/lib/python3.7/site-packages/werkzeug/security.py", line 153, in _hash_internal
rv = pbkdf2_hex(password, salt, iterations, hashfunc=method)
File "/usr/local/lib/python3.7/site-packages/werkzeug/security.py", line 53, in pbkdf2_hex
rv = pbkdf2_bin(data, salt, iterations, keylen, hashfunc)
File "/usr/local/lib/python3.7/site-packages/werkzeug/security.py", line 87, in pbkdf2_bin
return hashlib.pbkdf2_hmac(hash_name, data, salt, iterations, keylen)
TypeError: a bytes-like object is required, not 'NoneType'