我正在使用Cassandra DB和Django Framework,我试图从数据库中获取特定用户的部分信息,并尝试将其与用户输入进行比较,但不是返回输出,而是向我展示了一个“Unicode对象”没有属性项“错误
这是您参考的错误详情:
错误详情
AttributeError at /auth-user-session/
'unicode' object has no attribute 'items'
Request Method: POST
Request URL: http://127.0.0.1:8000/auth-user-session/
Django Version: 1.10.5
Exception Type: AttributeError
Exception Value:
'unicode' object has no attribute 'items'
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/base/operations.py in last_executed_query, line 215
Python Executable: /usr/bin/python
Python Version: 2.7.12
Python Path:
['/home/chamber/Desktop/Emergency-Command-Center-SOFTDEV/Application/Emergency-Command-Center',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/chamber/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Server time: Tue, 14 Mar 2017 08:08:05 +0000
回溯
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/auth-user-session/
Django Version: 1.10.5
Python Version: 2.7.12
Installed Applications:
['django_cassandra_engine',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'gentelella.core']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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']
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/chamber/Desktop/Emergency-Command-Center-SOFTDEV/Application/Emergency-Command-Center/gentelella/core/views.py" in LoginAuthPageView
79. result = cursor.execute("SELECT salt, password FROM emergency_command_center.auth_user_model WHERE username = ?", username)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py" in execute
83. sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/operations.py" in last_executed_query
215. u_params = {to_unicode(k): to_unicode(v) for k, v in params.items()}
Exception Type: AttributeError at /auth-user-session/
Exception Value: 'unicode' object has no attribute 'items'
这是代码:
views.py
def LoginAuthPageView(request):
if request.method == 'POST':
form = Login(request.POST)
if form.is_valid():
username = form.data['username']
password = form.data['password']
cursor = connection.cursor()
result = cursor.execute("SELECT salt, password FROM emergency_command_center.auth_user_model WHERE username = ?", username)
pword_hash = hashlib.sha512(password + result['salt']).hexdigest()
if(pword_hash == result['password']):
return HttpResponse(pword_hash)
我做错了吗?
答案 0 :(得分:0)
这个问题现在已经有些陈旧了,但是人们在搜索错误消息时仍然可以找到它:“ AttributeError:'unicode'对象没有属性'items'”
在我的情况下(youtube-dl),使用python3而不是python2解决了该问题。
可能其中一个涉及的.py文件仅使用python3-ism。