2010-11-15 91 views
1

我的註冊表在form.save()期間在我的自定義註冊表單的密碼字段中引發ValueError。「Unsupported hash type」error/Python 2.6.5 and django framework

以下是異常的詳細信息(從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.middleware.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可以在任何一個解決這個問題。 謝謝

+2

請問您可以重新格式化您的問題?使用101010按鈕標記代碼塊,以全英文說話,不要使所有內容都大膽。 – 2010-11-15 09:35:34

回答

1

haslib.new()期望哈希算法名稱(例如「md5」,「sha1」等)作爲第一個參數。你正在傳遞一個隨機字符串。

4

它看起來像你試圖用它來實現你自己的註冊框架。現有的有什麼問題?我認爲你應該通常閱讀更多關於Django框架的知識,並閱讀教程。

看着這個回溯,問題是在hashlib.new(str(random.random())).hexdigest()[:5]行。 (熟悉看着回溯和工作出來的問題是什麼,你會發現你需要經常,當你犯了一個錯誤。)

help(hashlib.new)表明這一點:

__hash_new(name, string='') 
    new(name, string='') - Return a new hashing object using the named algorithm; 
    optionally initialized with a string. 

的「命名的算法」應該是MD5,SHA1,SHA256等(用於列表,請參閱help(hashlib),以及如何你應該使用如hashlib.md5()代替hashlib.new('md5')

0

當密碼是在節省時間hashlib,而不是我用SH一個加密算法工作正常

相關問題