[docs] [issue10976] json.loads() raises TypeError on bytes object

Antoine Pitrou report at bugs.python.org
Thu Apr 26 18:12:45 CEST 2012

Antoine Pitrou <pitrou at free.fr> added the comment:

Le jeudi 26 avril 2012 à 15:48 +0000, Serhiy Storchaka a écrit :
> I mean a string that starts with '\u0000'. b'"\x00...'.

According to the RFC, that should be escaped:

   All Unicode characters may be placed within the
   quotation marks except for the characters that must be escaped:
   quotation mark, reverse solidus, and the control characters (U+0000
   through U+001F).

And indeed:

>>> json.loads('"\u0000"')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/antoine/opt/lib/python3.2/json/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/home/antoine/opt/lib/python3.2/json/decoder.py", line 351, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/antoine/opt/lib/python3.2/json/decoder.py", line 367, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Invalid control character at: line 1 column 1 (char 1)
>>> json.loads('"\\u0000"')


Python tracker <report at bugs.python.org>

More information about the docs mailing list