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 ezio.melotti
Recipients ezio.melotti, ncoghlan, pitrou, rhettinger, serhiy.storchaka
Date 2013-10-20.05:16:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382246199.49.0.284372498766.issue19307@psf.upfronthosting.co.za>
In-reply-to
Content
Currently the error raised when bytes are passed to json.loads() is not very clear:
>>> json.loads(b'')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wolf/dev/py/py3k/Lib/json/__init__.py", line 316, in loads
    return _default_decoder.decode(s)
  File "/home/wolf/dev/py/py3k/Lib/json/decoder.py", line 344, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: can't use a string pattern on a bytes-like object

The attached patch changes the error message to:
>>> json.loads(b'')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wolf/dev/py/py3k/Lib/json/__init__.py", line 315, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

(This came up on #18958, and it's required in order to check for a UTF-8 BOM without producing an even more misleading error message.)
History
Date User Action Args
2013-10-20 05:16:39ezio.melottisetrecipients: + ezio.melotti, rhettinger, ncoghlan, pitrou, serhiy.storchaka
2013-10-20 05:16:39ezio.melottisetmessageid: <1382246199.49.0.284372498766.issue19307@psf.upfronthosting.co.za>
2013-10-20 05:16:39ezio.melottilinkissue19307 messages
2013-10-20 05:16:39ezio.melotticreate