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 hhas
Recipients hhas
Date 2011-01-21.19:01:47
SpamBayes Score 1.2014438e-07
Marked as misclassified No
Message-id <1295636509.41.0.0138366952356.issue10976@psf.upfronthosting.co.za>
In-reply-to
Content
json.loads() accepts strings but errors on bytes objects. Documentation and API indicate that both should work. Review of json/__init__.py code shows that the loads() function's 'encoding' arg is ignored and no decoding takes place before the object is passed to JSONDecoder.decode()

Tested on Python 3.1.2 and Python 3.2rc1; fails on both. 

Example:

#################################################

#!/usr/local/bin/python3.2

import json

print(json.loads('123'))
# 123

print(json.loads(b'123'))
# /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/json/decoder.py:325:  
#   TypeError: can't use a string pattern on a bytes-like object

print(json.loads(b'123', encoding='utf-8'))
# /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/json/decoder.py:325:  
#   TypeError: can't use a string pattern on a bytes-like object

#################################################

Patch attached.
History
Date User Action Args
2011-01-21 19:01:49hhassetrecipients: + hhas
2011-01-21 19:01:49hhassetmessageid: <1295636509.41.0.0138366952356.issue10976@psf.upfronthosting.co.za>
2011-01-21 19:01:47hhaslinkissue10976 messages
2011-01-21 19:01:47hhascreate