Fix python3 Compatibility for hashlib md5 update

Without this change in Python3 it returns following:-
TypeError: Unicode-objects must be encoded before hashing

In Python3 encoding is explicitly needed, using encode method
or b"<string>" it can be achieved. Hashing examples with python([1])

[1] https://www.pythoncentral.io/hashing-strings-with-python/

Change-Id: I17ca99f00492633fa8e9e15558096792a48d204b
This commit is contained in:
yatin 2018-11-15 17:31:17 +05:30
parent 53b7115144
commit 7c2d6a970d
1 changed files with 2 additions and 2 deletions

View File

@ -121,7 +121,7 @@ class ClaimController(storage.Claim):
jsonutils.dumps(
{'body': msg['body'], 'claim_id': None,
'ttl': msg['ttl'],
'claim_count': claim_count}))
'claim_count': claim_count}).encode('utf-8'))
md5 = md5.hexdigest()
msg_ttl = max(msg['ttl'], msg_ts)
move_to_dlq = False
@ -224,7 +224,7 @@ class ClaimController(storage.Claim):
except errors.MessageDoesNotExist:
continue
md5 = hashlib.md5()
md5.update(msg)
md5.update(msg.encode('utf-8'))
md5 = md5.hexdigest()
msg = jsonutils.loads(msg)
content = jsonutils.dumps(