[GH-ISSUE #1798] Error with LDAP authentication - TypeError: 'NoneType' object is not iterable #1417

Closed
opened 2026-02-27 11:17:00 +03:00 by kerem · 3 comments
Owner

Originally created by @abonanni on GitHub (Dec 5, 2019).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/1798

Impacted versions

  • Modoboa: 1.1.14
  • Webserver: Nginx
  • django-auth-ldap: 1.7.0

Steps to reproduce

Configure an LDAP authentication backend and authenticate with a non existing database user (but existing in LDAP)

Current behavior

Une erreur interne est survenue.

You will find the log below :
Dec 5 14:07:05 modoboa django.request: ERROR Internal Server Error: /accounts/login/#012Traceback (most recent call last):#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner#012 response = get_response(request)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response#012 response = self.process_exception_by_middleware(e, request)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response#012 response = wrapped_callback(request, *callback_args, **callback_kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner#012 return func(*args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner#012 return func(*args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func#012 response = view_func(request, *args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/views/auth.py", line 36, in dologin#012 password=form.cleaned_data["password"])#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 70, in authenticate#012 user = _authenticate_with_backend(backend, backend_path, request, credentials)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 116, in _authenticate_with_backend#012 return backend.authenticate(*args, **credentials)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/authbackends.py", line 118, in authenticate#012 return super(LDAPBackend, self).authenticate(*args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 150, in authenticate#012 user = self.authenticate_ldap_user(ldap_user, password)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 210, in authenticate_ldap_user#012 return ldap_user.authenticate(password)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 350, in authenticate#012 self._get_or_create_user()#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 591, in _get_or_create_user#012 self._user, built = self.backend.get_or_build_user(username, self)#012TypeError: 'NoneType' object is not iterable

Expected behavior

Create user in database.

Originally created by @abonanni on GitHub (Dec 5, 2019). Original GitHub issue: https://github.com/modoboa/modoboa/issues/1798 # Impacted versions * Modoboa: 1.1.14 * Webserver: Nginx * django-auth-ldap: 1.7.0 # Steps to reproduce Configure an LDAP authentication backend and authenticate with a non existing database user (but existing in LDAP) # Current behavior Une erreur interne est survenue. You will find the log below : `Dec 5 14:07:05 modoboa django.request: ERROR Internal Server Error: /accounts/login/#012Traceback (most recent call last):#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner#012 response = get_response(request)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response#012 response = self.process_exception_by_middleware(e, request)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response#012 response = wrapped_callback(request, *callback_args, **callback_kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner#012 return func(*args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner#012 return func(*args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func#012 response = view_func(request, *args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/views/auth.py", line 36, in dologin#012 password=form.cleaned_data["password"])#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 70, in authenticate#012 user = _authenticate_with_backend(backend, backend_path, request, credentials)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 116, in _authenticate_with_backend#012 return backend.authenticate(*args, **credentials)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/authbackends.py", line 118, in authenticate#012 return super(LDAPBackend, self).authenticate(*args, **kwargs)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 150, in authenticate#012 user = self.authenticate_ldap_user(ldap_user, password)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 210, in authenticate_ldap_user#012 return ldap_user.authenticate(password)#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 350, in authenticate#012 self._get_or_create_user()#012 File "/srv/modoboa/env/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 591, in _get_or_create_user#012 self._user, built = self.backend.get_or_build_user(username, self)#012TypeError: 'NoneType' object is not iterable` # Expected behavior Create user in database.
kerem 2026-02-27 11:17:00 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@abonanni commented on GitHub (Dec 5, 2019):

I've changed the search filter with : (&(objectClass=user)(mail=%(user)s))
instead of (sAMAccountName=%(user)s) and it's better

<!-- gh-comment-id:562149893 --> @abonanni commented on GitHub (Dec 5, 2019): I've changed the search filter with : `(&(objectClass=user)(mail=%(user)s))` instead of `(sAMAccountName=%(user)s)` and it's better
Author
Owner

@tonioo commented on GitHub (Dec 17, 2019):

@abonanni what kind of username did you use to generate such an error? Was it an email address or an LDAP CN?

<!-- gh-comment-id:566443013 --> @tonioo commented on GitHub (Dec 17, 2019): @abonanni what kind of username did you use to generate such an error? Was it an email address or an LDAP CN?
Author
Owner

@abonanni commented on GitHub (Jan 3, 2020):

It was an LDAP CN, I want to use "sAMAccountName" to authenticate instead of email Address

<!-- gh-comment-id:570549118 --> @abonanni commented on GitHub (Jan 3, 2020): It was an LDAP CN, I want to use "sAMAccountName" to authenticate instead of email Address
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#1417
No description provided.