Message218579
In Python 2, json.loads() accepts str and unicode types. You can support JSON starting with a UTF-8 BOM using the Python codec "utf-8-sig". Example:
>>> codecs.BOM_UTF8 + b'{\n}'
'\xef\xbb\xbf{\n}'
>>> json.loads(codecs.BOM_UTF8 + b'{\n}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.7/json/decoder.py", line 383, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
>>> json.loads((codecs.BOM_UTF8 + b'{\n}').decode('utf-8-sig'))
{} |
|
Date |
User |
Action |
Args |
2014-05-14 21:49:58 | vstinner | set | recipients:
+ vstinner, Kristian.Benoit |
2014-05-14 21:49:58 | vstinner | set | messageid: <1400104198.9.0.0755359538288.issue21509@psf.upfronthosting.co.za> |
2014-05-14 21:49:58 | vstinner | link | issue21509 messages |
2014-05-14 21:49:58 | vstinner | create | |
|