Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

443
Vistas
AttributeError: 'NoneType' object has no attribute 'lower'; password validation

When registering a User, the desired user password is checked against a list of disallowed passwords. Yet when the password is passed to a validator method, the following error is raised:

AttributeError: 'NoneType' object has no attribute 'lower'

Why is the validate() method being invoked as is if password is None when in fact it is truthy?


from django.contrib.auth.models import User
from django.contrib.auth.password_validation import (
    validate_password, CommonPasswordValidator, NumericPasswordValidator
)

from rest_framework import serializers


class LoginSerializer(UsernameSerializer):

    password = serializers.RegexField(
        r"[0-9A-Za-z]+", min_length=5, max_length=8
    )

    def validate(self, data):
        username = data['username']
        password = data['password']
        try:
            validate_password(password, password_validators=[
                CommonPasswordValidator, NumericPasswordValidator
            ])
        except serializers.ValidationError:
            if username == password:
                pass
            raise serializers.ValidationError("Invalid password")
        else:
            return data

    class Meta:
        fields = ['username', 'password']
        model = User
-> for validator in password_validators:
(Pdb) n
> \auth\password_validation.py(46)validate_password()
-> try:
(Pdb) n
> \auth\password_validation.py(47)validate_password()
-> validator.validate(password, user)
(Pdb) password
'Bingo'
(Pdb) user
(Pdb) password
'Bingo'
(Pdb) s
--Call--
> \auth\password_validation.py(180)validate()
-> def validate(self, password, user=None):
(Pdb) password
(Pdb) n
> \django\contrib\auth\password_validation.py(181)validate()
-> if password.lower().strip() in self.passwords:
(Pdb) n
AttributeError: 'NoneType' object has no attribute 'lower'
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

if password and ...:

This checks if it has a value and if the value has the other conditions met

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda