After creating a user in my database in my application implemented in Heroku, I enter the registration page if it succeeds. When I try to log in, make the following query:
result = cur.execute("SELECT * FROM users WHERE username = %s", [username])
However, I get the following error:
018-07-03T15: 02: 47.167067 + 00: 00 app [web.1]: File "app.py", line 140, in login 2018-07-03T15: 02: 47.167069 + 00: 00 app [web.1]: if result > 0: 2018-07-03T15: 02: 47.167071 + 00: 00 app [web.1]: TypeError: '>' not supported between instances of 'NoneType' and 'int'
However, the registration query was successful and I am pretty sure that I provided the correct credentials. Here is the code involved:
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
# Get Form Fields
username = request.form['username']
password_candidate = request.form['password']
# Create cursor
#cur = mysql.connection.cursor()
cur = conn.cursor()
# Get user by username
result = cur.execute("SELECT * FROM users WHERE username = %s", [username])
if result > 0:
# Get stored hash
data = cur.fetchone()
password = data['password']