This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hynek
Recipients hynek, poppe1219, r.david.murray
Date 2012-10-10.09:58:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1349863123.04.0.411043009953.issue16179@psf.upfronthosting.co.za>
In-reply-to
Content
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"}'`.
History
Date User Action Args
2012-10-10 09:58:43hyneksetrecipients: + hynek, r.david.murray, poppe1219
2012-10-10 09:58:43hyneksetmessageid: <1349863123.04.0.411043009953.issue16179@psf.upfronthosting.co.za>
2012-10-10 09:58:42hyneklinkissue16179 messages
2012-10-10 09:58:42hynekcreate