You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2013-10-13.18:32:23.661>created_at=<Date2012-09-27.17:21:13.467>labels= ['type-bug', 'library']
title='HMAC trans_5C is a string, causing a TypeError'updated_at=<Date2013-10-13.18:32:23.660>user='https://bugs.python.org/AdamGlenn'
When passing 2 unicode objects to hmac.new() I'm getting "TypeError: character mapping must return integer, None or unicode" I've tried this using hashlib.sha1 and hashlib.md5 and the behavior is the same. What I think is happening is that the trans_5C join at the top of this module is a string so it's causing the type error when I try to generate the new hmac object at line 72.
I did some more testing and verified that this is a problem caused by the fact that trans_5C is a string and not unicode. It also happens when trans_36 is sent to key.translate().
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hmac
>>> hmac.new(u'key', u'msg')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "hmac.py", line 132, in new
return HMAC(key, msg, digestmod)
File "hmac.py", line 72, in __init__
self.inner.update(key.translate(trans_36))
TypeError: character mapping must return integer, None or unicode
>>>
That's to be expected. HMAC and all cryptographic hashing algorithms work with bytes only. Text (unicode) is neither specified by the standards nor supported. You have to convert your text to bytes with some encoding (e.g. ASCII or UTF-8).
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: