flask-security
flask-security copied to clipboard
SECURITY_MSG_PASSWORD_NOT_PROVIDED - Possible BUG
Hello,
Defining SECURITY_MSG_PASSWORD_NOT_PROVIDED in config.py, returns the following error, after you click the login button in the default form.
This usually happens when the field password is empty and you click twice.
Can you help me?
Thanks a lot.
TypeError TypeError: 'NoneType' object has no attribute 'getitem'
Traceback (most recent call last) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1997, in call error = None ctx.auto_pop(error)
def __call__(self, environ, start_response):
"""Shortcut for :attr:`wsgi_app`."""
return self.wsgi_app(environ, start_response)
def __repr__(self):
return '<%s %r>' % (
self.__class__.__name__,
self.name,
File "/usr/local/lib/python2.7/dist-packages/werkzeug/contrib/fixers.py", line 152, in call environ['REMOTE_ADDR'] = remote_addr if forwarded_host: environ['HTTP_HOST'] = forwarded_host if forwarded_proto: environ['wsgi.url_scheme'] = forwarded_proto return self.app(environ, start_response)
class HeaderRewriterFix(object):
"""This middleware can remove response headers and add others. This
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app try: try: response = self.full_dispatch_request() except Exception as e: error = e response = self.handle_exception(e) except: error = sys.exc_info()[1] raise return response(environ, start_response) finally: File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception # if we want to repropagate the exception, we can attempt to # raise it with the whole traceback in case we can do that # (the function was actually called from the except part) # otherwise, we just raise the error again if exc_value is e: reraise(exc_type, exc_value, tb) else: raise e
self.log_exception((exc_type, exc_value, tb))
if handler is None:
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app ctx = self.request_context(environ) ctx.push() error = None try: try: response = self.full_dispatch_request() except Exception as e: error = e response = self.handle_exception(e) except: error = sys.exc_info()[1] File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request request_started.send(self) rv = self.preprocess_request() if rv is None: rv = self.dispatch_request() except Exception as e: rv = self.handle_user_exception(e) return self.finalize_request(rv)
def finalize_request(self, rv, from_error_handler=False):
"""Given the return value from a view function this finalizes
the request by converting it into a response and invoking the
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception return self.handle_http_exception(e)
handler = self._find_error_handler(e)
if handler is None:
reraise(exc_type, exc_value, tb)
return handler(e)
def handle_exception(self, e):
"""Default exception handling that kicks in when an exception
occurs that is not caught. In debug mode the exception will
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request self.try_trigger_before_first_request_functions() try: request_started.send(self) rv = self.preprocess_request() if rv is None: rv = self.dispatch_request() except Exception as e: rv = self.handle_user_exception(e) return self.finalize_request(rv)
def finalize_request(self, rv, from_error_handler=False):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
# request came with the OPTIONS method, reply automatically
if getattr(rule, 'provide_automatic_options', False)
and req.method == 'OPTIONS':
return self.make_default_options_response()
# otherwise dispatch to the handler for that endpoint
return self.view_functionsrule.endpoint
def full_dispatch_request(self):
"""Dispatches the request and on top of that performs request
pre and postprocessing as well as HTTP exception catching and
error handling.
File "/usr/local/lib/python2.7/dist-packages/flask_security/decorators.py", line 230, in wrapper def anonymous_user_required(f): @wraps(f) def wrapper(*args, **kwargs): if current_user.is_authenticated: return redirect(utils.get_url(_security.post_login_view)) return f(*args, **kwargs) return wrapper File "/usr/local/lib/python2.7/dist-packages/flask_security/views.py", line 77, in login if request.is_json: form = form_class(MultiDict(request.get_json())) else: form = form_class(request.form)
if form.validate_on_submit():
login_user(form.user, remember=form.remember.data)
after_this_request(_commit)
if not request.is_json:
return redirect(get_post_login_redirect(form.next.data))
File "/usr/local/lib/python2.7/dist-packages/flask_wtf/form.py", line 101, in validate_on_submit
def validate_on_submit(self):
"""Call :meth:`validate` only if the form is submitted.
This is a shortcut for ``form.is_submitted() and form.validate()``.
"""
return self.is_submitted() and self.validate()
def hidden_tag(self, *fields):
"""Render the form's hidden fields in one call.
A field is considered hidden if it uses the
File "/usr/local/lib/python2.7/dist-packages/flask_security/forms.py", line 230, in validate message=get_message("FORGOT_PASSWORD")[0], )) self.password.description = html
def validate(self):
if not super(LoginForm, self).validate():
return False
self.user = _datastore.get_user(self.email.data)
if self.user is None:
File "/usr/local/lib/python2.7/dist-packages/wtforms/form.py", line 310, in validate for name in self.fields: inline = getattr(self.class, 'validate%s' % name, None) if inline is not None: extra[name] = [inline]
return super(Form, self).validate(extra)
File "/usr/local/lib/python2.7/dist-packages/wtforms/form.py", line 152, in validate for name, field in iteritems(self._fields): if extra_validators is not None and name in extra_validators: extra = extra_validators[name] else: extra = tuple() if not field.validate(self, extra): success = False return success
@property
def data(self):
File "/usr/local/lib/python2.7/dist-packages/wtforms/fields/core.py", line 204, in validate self.errors.append(e.args[0])
# Run validators
if not stop_validation:
chain = itertools.chain(self.validators, extra_validators)
stop_validation = self._run_validation_chain(form, chain)
# Call post_validate
try:
self.post_validate(form, stop_validation)
except ValueError as e:
File "/usr/local/lib/python2.7/dist-packages/wtforms/fields/core.py", line 224, in _run_validation_chain :param validators: a sequence or iterable of validator callables. :return: True if validation was stopped, False otherwise. """ for validator in validators: try: validator(form, self) except StopValidation as e: if e.args and e.args[0]: self.errors.append(e.args[0]) return True except ValueError as e: File "/usr/local/lib/python2.7/dist-packages/flask_security/forms.py", line 48, in call
class ValidatorMixin(object): def call(self, form, field): if self.message and self.message.isupper(): self.message = get_message(self.message)[0] return super(ValidatorMixin, self).call(form, field)
class EqualTo(ValidatorMixin, validators.EqualTo): pass File "/usr/local/lib/python2.7/dist-packages/flask_security/utils.py", line 334, in get_message return dict([strip_prefix(i) for i in items if i[0].startswith(prefix)])
def get_message(key, **kwargs): rv = config_value('MSG_' + key) return localize_callback(rv[0], **kwargs), rv[1]
def config_value(key, app=None, default=None): """Get a Flask-Security configuration value.
TypeError: 'NoneType' object has no attribute 'getitem'
This bug should be closed, it's incomprehensible. It seems likely that OP has not passed a valid tuple as explained here.