django - Django 登录 'NoneType' 对象没有属性 'append'
问题描述
Django Allauth 有问题。当我注销一个用户并与另一个用户重新登录时,我在本地和生产中都遇到了这个问题。
我正在使用最新版本的 Allauth、Django 3.0.5 和 Python 3.7.4。
这似乎是一个 Allauth 问题,但我还没有在其他任何地方看到它在网上报告过。所以只是想知道接下来我能做些什么来排除故障。登录工作正常,更少我刚刚退出另一个用户。
'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'
解决方案
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)
似乎由于某种原因,缓存正在存储None
登录尝试键的值(请注意,它忽略了默认值[]
)。CACHE
设置变量设置是否正确?
环顾四周, memcached 似乎存在一些问题,如果那是您正在使用的(编辑:我现在认为这是不可能的,因为如果结果是Django 代码只是将值设置为默认值None
,无论它是否实际上,由于python-memcached
限制,该密钥或密钥不存在)。这是非常奇怪的行为,您可以按照评论中的建议停用此功能,但这似乎是一个等待咬人的潜在问题。
推荐阅读
- r - 如何获取数字列表并将它们分成 2 类?
- stomp - 如果 TCP 已经保证了帧的传递,为什么 STOMP 协议有 ACK 和 NACK?
- c# - 如何阻止用户切换桌面
- python - AES OCB 加密无法正常工作的示例
- c++ - 有人可以解释特殊的 std::function 模板参数列表语法(这个奇怪的 Type(Types...))吗?
- javascript - Python vs Javascript MD5 对于大数字不同
- datagrid - Jboss JDG节点未加入集群
- sorting - react-bootstrap-table2 sortFunc 从未调用过
- javascript - 需要帮助消除滚动菜单上的不透明度
- javascript - 从 Node.js + Vue.js 中的远程 SFTP 服务器下载文件?