Message200545
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.) |
|
Date |
User |
Action |
Args |
2013-10-20 05:16:39 | ezio.melotti | set | recipients:
+ ezio.melotti, rhettinger, ncoghlan, pitrou, serhiy.storchaka |
2013-10-20 05:16:39 | ezio.melotti | set | messageid: <1382246199.49.0.284372498766.issue19307@psf.upfronthosting.co.za> |
2013-10-20 05:16:39 | ezio.melotti | link | issue19307 messages |
2013-10-20 05:16:39 | ezio.melotti | create | |
|