So I just got my first django app deployed.
我刚部署了我的第一个django应用。
I did a syncdb
and created my superuser account for the site.
我做了一个syncdb并为这个站点创建了我的超级用户帐户。
Now when I access the page and press the login button I get this error. I think it has something to do with the password but I'm not sure.
现在当我访问页面并按下登录按钮时,我就会得到这个错误。我认为这和密码有关,但我不确定。
ValueError at /accounts/login/
too many values to unpack
I'm using the generic login view
我使用的是通用登录视图
(r'^accounts/login/$', login, {'template_name': 'authentication/login.html'}),
The following is the traceback
下面是回溯
Environment:
Request Method: POST
Request URL: http://xx.xx.xx.xx:8888/accounts/login/?next=/some_page/
Django Version: 1.3.1
Python Version: 2.7.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'bc_system_app',
'django.contrib.humanize']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/views.py" in login
35. if form.is_valid():
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in is_valid
121. return self.is_bound and not bool(self.errors)
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in _get_errors
112. self.full_clean()
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in full_clean
268. self._clean_form()
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in _clean_form
296. self.cleaned_data = self.clean()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/forms.py" in clean
85. self.user_cache = authenticate(username=username, password=password)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py" in authenticate
55. user = backend.authenticate(**credentials)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py" in authenticate
18. if user.check_password(password):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in check_password
275. return check_password(raw_password, self.password)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in check_password
42. algo, salt, hsh = enc_password.split('$')
Exception Type: ValueError at /accounts/login/
Exception Value: too many values to unpack
6 个解决方案
#1
11
Yes, there is a problem in the password.
是的,密码有问题。
The error is in the way the password has been encrypted and stored in the DB. It can be clearly seen from the statement algo, salt, hsh = enc_password.split('$')
in the traceback. The encrypted password splitting returns more than 3 values.
错误在于密码被加密并存储在DB中。可以从traceback中的语句algo、salt、hsh = enc_password.split(“$”)中清楚地看到。加密的密码分割返回3个以上的值。
So, please have look at the password encryption schemes and related.
所以,请您看一下密码加密方案及相关内容。
#2
33
Just had the same problem.
只是有同样的问题。
It seem that in my case, the site was running with Django 1.4 when the password was created (due to a PYTHONPATH mix-up).
在我的例子中,当创建密码时,站点运行的是Django 1.4(由于PYTHONPATH出错)。
When I tried to login running the site with 1.3.1 I got this error. Then I noticed the Django version, switched to 1.4 and the login started working again.
当我尝试用1.3.1登录网站时,我得到了这个错误。然后我注意到了Django版本,切换到1.4,登录再次开始工作。
It seems the password algorithm was changed in 1.4:
密码算法似乎在1.4中被修改了:
https://docs.djangoproject.com/en/dev/releases/1.4-beta-1/#improved-password-hashing
https://docs.djangoproject.com/en/dev/releases/1.4-beta-1/ improved-password-hashing
And if you were using Django 1.4 alpha it might also be that the password was effectively corrupted (read the warning).
如果您使用的是Django 1.4 alpha,也可能是密码被有效破坏(请阅读警告)。
#3
18
The easiest fix is to reset your password from the command line.
最简单的解决方法是从命令行重置密码。
./manage.py changepassword <user>
#4
12
You can reset the password in the shell.
您可以重置shell中的密码。
from django.contrib.auth.models import User
u = User.objects.get(username="myuser")
u.set_password("mypassword")
u.save()
This happens when we downgrade from 1.4.X to test old deployments as detailed by @h3.
这发生在我们从1.4降级时。X测试由@h3详细说明的旧部署。
#5
2
I did everything to solve the same problem. Finally I deleted the db tables, and made syncdb again, creating new superuser. Everything works fine now. The problem is related to bad user data I guess.
我做了所有的事情来解决同样的问题。最后,我删除了db表,并再次生成syncdb,创建新的超级用户。现在,一切工作正常。我认为这个问题与坏的用户数据有关。
#6
0
I had a similar problem. The password for my superuser was somehow corrupted. You can check this by examining the auth_user table in your database. Your password should be something like ""sha1$263a7$c17f83f1d1902fb7bd527d00ffcb22f4dc97a978". If you have more than (or less than) two "$" symbols, you would get a similar error. The reason for this, as Sandip mentioned, is because the following function expects three values to be returned:
我也有类似的问题。我的超级用户的密码不知怎么被破坏了。您可以通过检查数据库中的auth_user表来检查这一点。您的密码应该类似于“sha1$263a7$c17f83f1d1902fb7bd527d00ffcb22f4dc97a978”。如果您有多于(或少于)两个“$”符号,您将得到类似的错误。正如Sandip提到的,这是因为以下函数期望返回三个值:
algo, salt, hsh = enc_password.split('$')
algo, salt, hsh = enc_password.split('$')
Having that extra "$" symbol in your password would return four values and cause the "too many values to unpack" error message to appear.
在您的密码中使用额外的“$”符号将返回4个值,并导致出现“要解包的值太多”的错误消息。
The solution for me was to create a new superuser by using the createsuperuser command in the manage.py script. More information about how to create a superuser can be found here:
我的解决方案是在管理中使用createsuperuser命令创建一个新的超级用户。py脚本。关于如何创建超级用户的更多信息可以在这里找到:
https://docs.djangoproject.com/en/dev/topics/auth/
https://docs.djangoproject.com/en/dev/topics/auth/
I am still not sure why my password was corrupted.
我仍然不确定为什么我的密码被破坏了。
#1
11
Yes, there is a problem in the password.
是的,密码有问题。
The error is in the way the password has been encrypted and stored in the DB. It can be clearly seen from the statement algo, salt, hsh = enc_password.split('$')
in the traceback. The encrypted password splitting returns more than 3 values.
错误在于密码被加密并存储在DB中。可以从traceback中的语句algo、salt、hsh = enc_password.split(“$”)中清楚地看到。加密的密码分割返回3个以上的值。
So, please have look at the password encryption schemes and related.
所以,请您看一下密码加密方案及相关内容。
#2
33
Just had the same problem.
只是有同样的问题。
It seem that in my case, the site was running with Django 1.4 when the password was created (due to a PYTHONPATH mix-up).
在我的例子中,当创建密码时,站点运行的是Django 1.4(由于PYTHONPATH出错)。
When I tried to login running the site with 1.3.1 I got this error. Then I noticed the Django version, switched to 1.4 and the login started working again.
当我尝试用1.3.1登录网站时,我得到了这个错误。然后我注意到了Django版本,切换到1.4,登录再次开始工作。
It seems the password algorithm was changed in 1.4:
密码算法似乎在1.4中被修改了:
https://docs.djangoproject.com/en/dev/releases/1.4-beta-1/#improved-password-hashing
https://docs.djangoproject.com/en/dev/releases/1.4-beta-1/ improved-password-hashing
And if you were using Django 1.4 alpha it might also be that the password was effectively corrupted (read the warning).
如果您使用的是Django 1.4 alpha,也可能是密码被有效破坏(请阅读警告)。
#3
18
The easiest fix is to reset your password from the command line.
最简单的解决方法是从命令行重置密码。
./manage.py changepassword <user>
#4
12
You can reset the password in the shell.
您可以重置shell中的密码。
from django.contrib.auth.models import User
u = User.objects.get(username="myuser")
u.set_password("mypassword")
u.save()
This happens when we downgrade from 1.4.X to test old deployments as detailed by @h3.
这发生在我们从1.4降级时。X测试由@h3详细说明的旧部署。
#5
2
I did everything to solve the same problem. Finally I deleted the db tables, and made syncdb again, creating new superuser. Everything works fine now. The problem is related to bad user data I guess.
我做了所有的事情来解决同样的问题。最后,我删除了db表,并再次生成syncdb,创建新的超级用户。现在,一切工作正常。我认为这个问题与坏的用户数据有关。
#6
0
I had a similar problem. The password for my superuser was somehow corrupted. You can check this by examining the auth_user table in your database. Your password should be something like ""sha1$263a7$c17f83f1d1902fb7bd527d00ffcb22f4dc97a978". If you have more than (or less than) two "$" symbols, you would get a similar error. The reason for this, as Sandip mentioned, is because the following function expects three values to be returned:
我也有类似的问题。我的超级用户的密码不知怎么被破坏了。您可以通过检查数据库中的auth_user表来检查这一点。您的密码应该类似于“sha1$263a7$c17f83f1d1902fb7bd527d00ffcb22f4dc97a978”。如果您有多于(或少于)两个“$”符号,您将得到类似的错误。正如Sandip提到的,这是因为以下函数期望返回三个值:
algo, salt, hsh = enc_password.split('$')
algo, salt, hsh = enc_password.split('$')
Having that extra "$" symbol in your password would return four values and cause the "too many values to unpack" error message to appear.
在您的密码中使用额外的“$”符号将返回4个值,并导致出现“要解包的值太多”的错误消息。
The solution for me was to create a new superuser by using the createsuperuser command in the manage.py script. More information about how to create a superuser can be found here:
我的解决方案是在管理中使用createsuperuser命令创建一个新的超级用户。py脚本。关于如何创建超级用户的更多信息可以在这里找到:
https://docs.djangoproject.com/en/dev/topics/auth/
https://docs.djangoproject.com/en/dev/topics/auth/
I am still not sure why my password was corrupted.
我仍然不确定为什么我的密码被破坏了。