Opened 14 years ago
Closed 14 years ago
#13653 closed (fixed)
Python 2.4 + hashlib causes AttributeError calling hmac.new()
Reported by: | Karen Tracey | Owned by: | Karen Tracey |
---|---|---|---|
Component: | Core (Other) | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you install the standalone hashlib module on Python 2.4, attempting to do anything the admin that requires creation of a message results in an error:
Traceback (most recent call last): File "C:\u\kmt\django\trunk\django\core\servers\basehttp.py", line 280, in run self.result = application(self.environ, self.start_response) File "C:\u\kmt\django\trunk\django\core\servers\basehttp.py", line 674, in __call__ return self.application(environ, start_response) File "C:\u\kmt\django\trunk\django\core\handlers\wsgi.py", line 245, in __call__ response = middleware_method(request, response) File "C:\u\kmt\django\trunk\django\contrib\messages\middleware.py", line 23, in process_response unstored_messages = request._messages.update(response) File "C:\u\kmt\django\trunk\django\contrib\messages\storage\base.py", line 138, in update return self._store(messages, response) File "C:\u\kmt\django\trunk\django\contrib\messages\storage\fallback.py", line 48, in _store remove_oldest=False) File "C:\u\kmt\django\trunk\django\contrib\messages\storage\cookie.py", line 91, in _store encoded_data = self._encode(messages) File "C:\u\kmt\django\trunk\django\contrib\messages\storage\cookie.py", line 128, in _encode return '%s$%s' % (self._hash(value), value) File "C:\u\kmt\django\trunk\django\contrib\messages\storage\cookie.py", line 115, in _hash return hmac.new(key, value, sha_hmac).hexdigest() File "C:\bin\Python24\lib\hmac.py", line 107, in new return HMAC(key, msg, digestmod) File "C:\bin\Python24\lib\hmac.py", line 42, in __init__ self.outer = digestmod.new() AttributeError: 'builtin_function_or_method' object has no attribute 'new'
The django.utils.hashcompat
module assumes that if hashlib imports without error, then the whole stdlib is 2.5. But when running on 2.4+standalone hashlib, we've got 2.4 hmac, and the sha_hmac value set in hashcompat needs to be the one for 2.4, not the value that works for 2.5+ and is set when the hashlib import succeeds.
Change History (2)
comment:1 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
(In [13310]) Fixed #13653: Fixed django.utils.hashcompat to support running on Python 2.4 with standalone hashlib.