[英]Django login 'NoneType' object has no attribute 'append'
Having an issue with Django Allauth. Django Allauth 存在问题。 When I log out of one user, and log back in with another, I get this issue, both locally and in production.
当我注销一个用户并与另一个用户重新登录时,我在本地和生产中都遇到了这个问题。
I'm using the latest version of Allauth, Django 3.0.5, and Python 3.7.4.我正在使用最新版本的 Allauth,Django 3.0.5 和 Python 3.7.4。
It seems like this is an Allauth issue, but I haven't seen it reported online anywhere else.这似乎是一个 Allauth 问题,但我还没有在其他任何地方看到它在网上报告过。 So just wondering what I can do next to troubleshoot.
所以只是想知道接下来我能做些什么来排除故障。 Login works fine, less I just logged out of another user.
登录工作正常,更少我刚刚退出另一个用户。
'NoneType' object has no attribute 'append'
Request Method: POST
Request URL: http://127.0.0.1:8000/account/login/
Django Version: 3.0.5
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'append'
Exception Location: /Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/allauth/account/adapter.py in authentication_failed, line 507
Python Executable: /Users/[USERDIR]/Sites/frontline/venv/bin/python
Python Version: 3.7.4
Python Path:
['/Users/[USERDIR]/Sites/frontline',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python37.zip',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/odf',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/odf',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/odf',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/odf',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/odf',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/odf',
'/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/odf']
Server time: Thu, 16 Apr 2020 17:53:52 -0700
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/account/login/
Django Version: 3.0.5
Python Version: 3.7.4
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.postgres',
'common',
'bootstrap4',
's3direct',
'bootstrap_datepicker_plus',
'import_export',
'tinymce',
'allauth',
'allauth.account',
'allauth.socialaccount',
'debug_toolbar',
'dashboard',
'marketing']
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback (most recent call last):
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/allauth/account/views.py", line 138, in dispatch
return super(LoginView, self).dispatch(request, *args, **kwargs)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/allauth/account/views.py", line 81, in dispatch
**kwargs)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/allauth/account/views.py", line 103, in post
if form.is_valid():
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/forms/forms.py", line 180, in is_valid
return self.is_bound and not self.errors
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/forms/forms.py", line 175, in errors
self.full_clean()
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/forms/forms.py", line 377, in full_clean
self._clean_form()
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/django/forms/forms.py", line 404, in _clean_form
cleaned_data = self.clean()
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/allauth/account/forms.py", line 179, in clean
**credentials)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/allauth/account/adapter.py", line 497, in authenticate
self.authentication_failed(request, **credentials)
File "/Users/[USERDIR]/Sites/frontline/venv/lib/python3.7/site-packages/allauth/account/adapter.py", line 507, in authentication_failed
data.append(time.mktime(dt.timetuple()))
Exception Type: AttributeError at /account/login/
Exception Value: 'NoneType' object has no attribute 'append'
Put your allauth
packages to the top of installed apps and try again.将您的
allauth
包放在已安装应用程序的顶部,然后重试。 It can be a problem of conflicts since the default django.contrib.auth
package is on the top of hierarchy and when django looks through the installed apps, it stops on the first one that matches it's criteria.这可能是一个冲突问题,因为默认的
django.contrib.auth
package 位于层次结构的顶部,当 django 查看已安装的应用程序时,它会在第一个匹配的应用程序上停止。
Looking at the allauth
code ,查看
allauth
代码,
def authentication_failed(self, request, **credentials):
if app_settings.LOGIN_ATTEMPTS_LIMIT:
cache_key = self._get_login_attempts_cache_key(
request, **credentials
)
data = cache.get(cache_key, [])
dt = timezone.now()
data.append(time.mktime(dt.timetuple()))
cache.set(cache_key, data, app_settings.LOGIN_ATTEMPTS_TIMEOUT)
it seems that for some reason the cache is storing a None
value for the login attempts key (note that it's ignoring the default value, []
).似乎由于某种原因,缓存正在为登录尝试键存储
None
值(请注意,它忽略了默认值[]
)。 Is the CACHE
settings variable set-up correctly ? CACHE
设置变量设置是否正确?
Looking around, there seems to be some issues with memcached , if that's what you're using ( Edit: I now think that isn't possible since the Django code just sets the value to the default if the result is None
, no matter if it's actually that or the key is not present, due topython-memcached
limitations ).环顾四周, memcached 似乎存在一些问题,如果那是您正在使用的(编辑:我现在认为这是不可能的,因为 Django 代码只是将值设置为默认值,如果结果为
None
,无论是否实际上是这样,或者由于python-memcached
限制,密钥不存在)。 This is very strange behavior, you could just deactivate this feature as suggested in the comments, but it seems to be an underlying issue waiting to bite.这是非常奇怪的行为,您可以按照评论中的建议停用此功能,但这似乎是一个等待咬人的潜在问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.