Message126772
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. |
|
Date |
User |
Action |
Args |
2011-01-21 19:01:49 | hhas | set | recipients:
+ hhas |
2011-01-21 19:01:49 | hhas | set | messageid: <1295636509.41.0.0138366952356.issue10976@psf.upfronthosting.co.za> |
2011-01-21 19:01:47 | hhas | link | issue10976 messages |
2011-01-21 19:01:47 | hhas | create | |
|