Hynek Schlawack added the comment:

Actually, that’s not the point here, the code has a deeper flaw.

You’re computing hashlib.md5() on `data.encode()` and `str(jsonData).encode()`. 
Did you have a look how they look like?

>>> data.encode()
b'{"key1":"value1","key2":"value2"}'
[71875 refs]
>>> str(jsonData).encode()
b"{'key1': 'value1', 'key2': 'value2'}"

`str(jsonData)` doesn’t return JSON because it’s a simple dict():

>>> type(jsonData)
<class 'dict'>

If you wanted to have JSON again, you’d have to use `json.dumps()`:

>>> json.dumps(jsonData)
'{"key1": "value1", "key2": "value2"}'

HOWEVER: This string _also_ differs from yours due to additional whitespace, 
ie. the sum would differ again.

Additionally, as David pointed out, you can’t rely on the order of the dict. 
json.dump() could just as well return `'{"key2": "value2", "key1": "value1"}'`.

----------
nosy: +hynek

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16179>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to