Forums

error with flask-security

I installed flask-security via pip install flask-security, and it worked fine.

Then I copy-pasted the basic example from the flask-security website here: https://pythonhosted.org/Flask-Security/quickstart.html#id1

It shows the login form, but once I enter the details of the user and hit the login button, pythonAnywhere throws an exception:

Error running WSGI application
NameError: name 'RoleMixin' is not defined
File "/var/www/..._pythonanywhere_com_wsgi.py", line 16, in <module>
from flask_app import app as application

 File "/home/.../mysite/flask_app.py", line 29, in <module>
class Role(db.Model, RoleMixin):

Error running WSGI application
NameError: name 'RoleMixin' is not defined
 File "/var/www/..._pythonanywhere_com_wsgi.py", line 16, in <module>
 from flask_app import app as application

 File "/home/.../mysite/flask_app.py", line 29, in <module>
class Role(db.Model, RoleMixin):

 Error running WSGI application
 RuntimeError: The configuration value `SECURITY_PASSWORD_SALT` must not be None when the value of `SECURITY_PASSWORD_HASH` is set to "bcrypt"
   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1994, in __call__
     return self.wsgi_app(environ, start_response)

I've got no clue what goes wrong here, so I would appreciate any help pointing to my mistake.

[edit by admin: formatting]

For the first error, are you sure you're importing RoleMixin from flask_security in your code?

For the second one, are you setting app.config['SECURITY_PASSWORD_SALT'] to something?

I don't worry too much about the second error, the first one seems more crucial.

So far I also think that's the problem, that RoleMixin is not loaded.

However, I use

from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy from flask_security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin, login_required

But there seems to be no problem with UserMixin. Actually, another case where this has been code exactly like this is here: https://github.com/mattupstate/flask-security-example/blob/master/app.py (the difference being that there, login_required is not used, whereas it is used in the official flask-security documentation).

So RoleMixin is a function inside flask_security, I guess. So it can't be that it has not been installed, can it? I guess that I must be making some more basic mistake.

Can I take a look at your code? We can see it from our admin interface, but we always ask for permission first.

Yes, feel free to look at it. It feels a bit stupid that I cannot resolve it, I am sure it must be some obvious step that I am overlooking.

Hi there, the latest error i'm seeing in your log files is

RuntimeError: The configuration value `SECURITY_PASSWORD_SALT` must not be None when the value of `SECURITY_PASSWORD_HASH` is set to "bcrypt"

so maybe that's a different issue now?