Opened 9 years ago

Closed 9 years ago

#13653 closed (fixed)

Python 2.4 + hashlib causes AttributeError calling

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


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\", line 280, in run
    self.result = application(self.environ, self.start_response)

  File "C:\u\kmt\django\trunk\django\core\servers\", line 674, in __call__
    return self.application(environ, start_response)

  File "C:\u\kmt\django\trunk\django\core\handlers\", line 245, in __call__
    response = middleware_method(request, response)

  File "C:\u\kmt\django\trunk\django\contrib\messages\", line 23, in process_response
    unstored_messages = request._messages.update(response)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\", line 138, in update
    return self._store(messages, response)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\", line 48, in _store

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\", line 91, in _store
    encoded_data = self._encode(messages)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\", line 128, in _encode
    return '%s$%s' % (self._hash(value), value)

  File "C:\u\kmt\django\trunk\django\contrib\messages\storage\", line 115, in _hash
    return, value, sha_hmac).hexdigest()

  File "C:\bin\Python24\lib\", line 107, in new
    return HMAC(key, msg, digestmod)

  File "C:\bin\Python24\lib\", line 42, in __init__
    self.outer =

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 Changed 9 years ago by Karen Tracey

Owner: changed from nobody to Karen Tracey
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 Changed 9 years ago by Karen Tracey

Resolution: fixed
Status: assignedclosed

(In [13310]) Fixed #13653: Fixed django.utils.hashcompat to support running on Python 2.4 with standalone hashlib.

Note: See TracTickets for help on using tickets.
Back to Top