"Unsupported hash type" error w/ Python 2.6.5 and django framework
My registration form is throwing a ValueError during form.save()
in my custom registration form's password field.
Here are the exception details (copied from http://www.pastie.org/1299144):
Environment:
Request Method: POST
Request URL: http://192.168.2.206:8080/register/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.markup',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.comments',
'mysite.registration',
'mysite.profiles',
'mysite.epw',
'mysite.remember_me',
'mysite.avatar',
'mysite.django_documents',
'mysite.inlines',
'mysite.blog',
'mysite.forum',
'tagging']
Installed Middleware:
('django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'django.contrib.sessions.middl开发者_JAVA技巧eware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'mysite.remember_me.views.AutoLogout')
Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in _wrapped_view
48. response = view_func(request, *args, **kwargs)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/epw/views.py" in register
1538. new_user = form.save(request)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/epw/form.py" in save
169. profile_callback=profile_callback)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/registration/models.py" in create_inactive_user
110. registration_profile = self.create_profile(new_user)
File "/home/karthik/Desktop/EPW_LOCAL/mysite/../mysite/registration/models.py" in create_profile
145. salt = hashlib.new(str(random.random())).hexdigest()[:5]
File "/usr/lib/python2.6/hashlib.py" in __hash_new
101. return __get_builtin_constructor(name)(string)
File "/usr/lib/python2.6/hashlib.py" in __get_builtin_constructor
80. raise ValueError, "unsupported hash type"
Exception Type: ValueError at /register/
Exception Value: unsupported hash type
pls could any one resolve this. thanks
It looks like you're trying to implement your own registration framework with it. What's wrong with the existing one? I think you should read more about the Django framework generally and go through the tutorial.
Looking at that traceback, the problem is in the line hashlib.new(str(random.random())).hexdigest()[:5]
. (Get familiar with looking at tracebacks and working out what the issue is, you'll find you need to often when you make a mistake.)
help(hashlib.new)
shows this:
__hash_new(name, string='')
new(name, string='') - Return a new hashing object using the named algorithm;
optionally initialized with a string.
The "named algorithm" should be md5, sha1, sha256, etc. (See help(hashlib)
for the list, and also how you should use e.g. hashlib.md5()
instead of hashlib.new('md5')
.)
haslib.new()
expects a hashing algorithm name (e.g. "md5", "sha1" etc.) as the first parameter. You're passing in a random string.
when the password is saving at the time instead of hashlib i use sha cryptographic alog that works fine
精彩评论