'Flask Login is not working properly on Python Anywhere

This morning I tried to login in my account from my website(deployed on python anywhere). I typed my credentials and then I got a Server Error.

The Error:

Traceback (most recent call last):
  File "/home/Vomindo/.virtualenvs/my-virtualenv/lib/python3.6/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/Vomindo/.virtualenvs/my-virtualenv/lib/python3.6/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/Vomindo/.virtualenvs/my-virtualenv/lib/python3.6/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/Vomindo/.virtualenvs/my-virtualenv/lib/python3.6/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/Vomindo/mysite/main.py", line 463, in logmein
    spass = check_password_hash(user.password, password)
AttributeError: 'NoneType' object has no attribute 'password'

After that, I tried to login from my main device. It worked perfectly. I checked if I entered the same credentials and I did.

The view function:

@application.route('/logmein', methods=['POST'])
def logmein():

    password = request.form['password']
    email = request.form['email']

    user = User.query.filter_by(email=email).first()
    spass = check_password_hash(user.password, password)

    if not user:
        return '<h1>We could not find the account!<a href="/login">try again</a></h1>'
    else:
        if spass == True:

           login_user(user, remember=True)
           return redirect('/')
        else:
           return '<body style="background: yellow"><h1>The password is incorrect! <a href="/login"> go back</a></h1></body>'

Thanks for help!!!



Solution 1:[1]

You should see whats being sent over when you post by printing the form data.

@application.route('/logmein', methods=['POST'])
def logmein():
    print(request.form)

    # print each method so you can look around
    print(dir(request.form))
    return 'test'

AttributeError: 'NoneType' object has no attribute 'password' < Leads me to beleive the issue is that password doesnt exist as you reference it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nathan Getty