flask_wtf: TypeError: validate() got an unexpected keyword argument 'extra_validators'

732 Views Asked by At

I'm new to the web and can't find a solution myself, please help. I have a simple flask web app, and i use flask-admin to create an admin panel and when i try to login to the admin panel, i see an error:

Traceback (most recent call last):
  File "D:\flask_app\lib\site-packages\flask\app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "D:\flask_app\lib\site-packages\flask\app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "D:\flask_app\lib\site-packages\flask\app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "D:\flask_app\lib\site-packages\flask\app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "D:\flask_app\lib\site-packages\flask_security\decorators.py", line 230, in wrapper
    return f(*args, **kwargs)
  File "D:\flask_app\lib\site-packages\flask_security\views.py", line 77, in login
    if form.validate_on_submit():
  File "D:\flask_app\lib\site-packages\flask_wtf\form.py", line 86, in validate_on_submit
    return self.is_submitted() and self.validate(extra_validators=extra_validators)
TypeError: validate() got an unexpected keyword argument 'extra_validators'

requirements for py39

Flask==2.3.2  
Flask-Admin==1.6.1   
Flask-Security==3.0.0
WTForms==3.0.1 # 3.0.0/2.3.3 I also checked these versions.
 

I've wasted enough time and I can't figure out why this is happening :(

I tried to install different versions of the package, but nothing happened

Here is my admin.py:

class AdminMixin:     
    def is_accessible(self):         
        return current_user.has_role('admin')      
    def inaccessible_callback(self, name, **kwargs):
         return redirect(url_for('security.login', next=request.url))   

class AdminView(AdminMixin, ModelView):
     pass   

class HomeAdminView(AdminMixin, AdminIndexView):     
     pass   

admin = Admin(app, 'Flask', url='/', index_view=HomeAdminView())  
admin.add_view(AdminView(User, db.session))  
user_datastore = SQLAlchemyUserDatastore(db, User, Role) 
security = Security(app, user_datastore)
1

There are 1 best solutions below

0
pdavby On

i did research, this is the problem of flask_security\forms.py in LoginForm class validation method - missing extra_validators=None in args

def validate(self):
    if not super(LoginForm, self).validate():
        return False

    self.user = _datastore.get_user(self.email.data)

    if self.user is None:
        self.email.errors.append(get_message('USER_DOES_NOT_EXIST')[0])
        return False
    if not self.user.password:
        self.password.errors.append(get_message('PASSWORD_NOT_SET')[0])
        return False
    if not verify_and_update_password(self.password.data, self.user):
        self.password.errors.append(get_message('INVALID_PASSWORD')[0])
        return False
    if requires_confirmation(self.user):
        self.email.errors.append(get_message('CONFIRMATION_REQUIRED')[0])
        return False
    if not self.user.is_active:
        self.email.errors.append(get_message('DISABLED_ACCOUNT')[0])
        return False
    return True

solution:

pip install Flask-Security-Fork

this is a copy of the Flask-Securit in which problems are quickly solved