question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'NoneType' object is not subscriptable when authenticating user

See original GitHub issue

I have a Mezzanine CMS using Django’s LDAP authentication backend. Authenticating a user causes a crash in django-auth-ldap code. I’m just setting up the LDAP authentication so there may be some error in the setup, but username and password should be correct and anyway correct behavior would be to throw a proper exception.

Quickly looking seems that self.attrs[attr] is None and there is no check for it, causing the error.

`Environment:

Request Method: POST Request URL: http://staging.tampere.hacklab.fi/admin/login/?next=/admin/

Django Version: 1.11.15 Python Version: 3.6.6 Installed Applications: (‘mezzanine.boot’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.redirects’, ‘django.contrib.sessions’, ‘django.contrib.sites’, ‘django.contrib.sitemaps’, ‘mezzanine.conf’, ‘mezzanine.core’, ‘mezzanine.generic’, ‘mezzanine.pages’, ‘mezzanine.blog’, ‘mezzanine.forms’, ‘mezzanine.galleries’, ‘mezzanine.twitter’, ‘filebrowser_safe’, ‘grappelli_safe’, ‘django.contrib.admin’, ‘django.contrib.staticfiles’, ‘django_comments’) Installed Middleware: (‘django.contrib.sessions.middleware.SessionMiddleware’, ‘django.middleware.common.CommonMiddleware’, ‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.contrib.auth.middleware.AuthenticationMiddleware’, ‘django.contrib.auth.middleware.SessionAuthenticationMiddleware’, ‘django.contrib.messages.middleware.MessageMiddleware’, ‘django.middleware.clickjacking.XFrameOptionsMiddleware’, ‘mezzanine.core.request.CurrentRequestMiddleware’, ‘mezzanine.core.middleware.RedirectFallbackMiddleware’, ‘mezzanine.core.middleware.TemplateForDeviceMiddleware’, ‘mezzanine.core.middleware.TemplateForHostMiddleware’, ‘mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware’, ‘mezzanine.core.middleware.SitePermissionMiddleware’, ‘mezzanine.pages.middleware.PageMiddleware’)

Traceback:

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/core/handlers/exception.py” in inner 41. response = get_response(request)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/core/handlers/base.py” in _legacy_get_response 249. response = self._get_response(request)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/core/handlers/base.py” in _get_response 178. response = middleware_method(request, callback, callback_args, callback_kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/mezzanine/core/middleware.py” in process_view 40. response = view_func(request, *view_args, **view_kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/views/decorators/cache.py” in _wrapped_view_func 57. response = view_func(request, *args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/contrib/admin/sites.py” in login 393. return LoginView.as_view(**defaults)(request)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/views/generic/base.py” in view 68. return self.dispatch(request, *args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/utils/decorators.py” in _wrapper 67. return bound_func(*args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/views/decorators/debug.py” in sensitive_post_parameters_wrapper 76. return view(request, *args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/utils/decorators.py” in bound_func 63. return func.get(self, type(self))(*args2, **kwargs2)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/utils/decorators.py” in _wrapper 67. return bound_func(*args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/utils/decorators.py” in _wrapped_view 149. response = view_func(request, *args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/utils/decorators.py” in bound_func 63. return func.get(self, type(self))(*args2, **kwargs2)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/utils/decorators.py” in _wrapper 67. return bound_func(*args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/views/decorators/cache.py” in _wrapped_view_func 57. response = view_func(request, *args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/utils/decorators.py” in bound_func 63. return func.get(self, type(self))(*args2, **kwargs2)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/contrib/auth/views.py” in dispatch 90. return super(LoginView, self).dispatch(request, *args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/views/generic/base.py” in dispatch 88. return handler(request, *args, **kwargs)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/views/generic/edit.py” in post 182. if form.is_valid():

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/forms/forms.py” in is_valid 183. return self.is_bound and not self.errors

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/forms/forms.py” in errors 175. self.full_clean()

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/forms/forms.py” in full_clean 385. self._clean_form()

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/forms/forms.py” in _clean_form 412. cleaned_data = self.clean()

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/contrib/auth/forms.py” in clean 187. self.user_cache = authenticate(self.request, username=username, password=password)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/contrib/auth/init.py” in authenticate 70. user = _authenticate_with_backend(backend, backend_path, request, credentials)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django/contrib/auth/init.py” in _authenticate_with_backend 116. return backend.authenticate(*args, **credentials)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django_auth_ldap/backend.py” in authenticate 150. user = self.authenticate_ldap_user(ldap_user, password)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django_auth_ldap/backend.py” in authenticate_ldap_user 210. return ldap_user.authenticate(password)

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django_auth_ldap/backend.py” in authenticate 350. self._get_or_create_user()

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django_auth_ldap/backend.py” in _get_or_create_user 604. self._populate_user()

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django_auth_ldap/backend.py” in _populate_user 623. self._populate_user_from_attributes()

File “/mezzanine/virtualenv/lib/python3.6/site-packages/django_auth_ldap/backend.py” in _populate_user_from_attributes 629. value = self.attrs[attr][0]

Exception Type: TypeError at /admin/login/ Exception Value: ‘NoneType’ object is not subscriptable `

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vrankicommented, Oct 19, 2018

I did the same change and it seemed to work. AUTH_LDAP_USER_DN_TEMPLATE seems to be broken at the moment. My configuration worked with older version so this is a regression.

0reactions
jdufresnecommented, Oct 26, 2018

Could someone in this thread test #102 and report back please? I’m unable to craft a real world scenario but believe it will fix the case for the provided stack trace. If it passes for you, I’ll merge and release. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: 'NoneType' object is not subscriptable
None always has no data and can not be subscriptable. In general, the error means that you attempted to index an object that...
Read more >
'NoneType' object is not subscriptable - python - Stack Overflow
I am creating an ios app that uses a server written in flask + python, and when I make a connection to the...
Read more >
Django error: 'NoneType' object is not subscriptable-django
it seems to me that the form instance rf doesn't have a cleaned_data field. The 'NoneType' object is unsubscriptable error can be raised...
Read more >
'NoneType' object is not subscriptable when posting from app ...
TypeError : 'NoneType' object is not subscriptable when posting from app but not from PostMan. Hey Y'all,. I'm having this issue with my...
Read more >
typeerror 'nonetype' object is not subscriptable stackoverflow
Check the NoneType object. You can use the Authentication operator to check if a variable can validly call append(). Example: Declare a variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found