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.

classification
Title: json.load should handle bytes input
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: jfinkels, martin.panter
Priority: normal Keywords:

Created on 2010-11-11 16:50 by jfinkels, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg120960 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-11-11 16:50
The following code produces an error:

# APIKEY defined above
r = urllib.request.urlopen('http://api.billboard.com/apisvc/chart/v1/'
                           'list/spec?api_key={}&format=JSON'
                           .format(APIKEY))
j = json.load(r)

Specifically, the urlopen() function returns a request object that can be read, the request object returns a bytes object containing JSON, and the json.load() function tries to mix str and bytes objects when using the re module.

json.load() should convert bytes to str. It is reasonable that one should be able to open a url and pass the result directly to json.load().
msg120961 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-11-11 16:53
Nevermind.
msg229972 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2014-10-25 01:00
See also Issue 10976, discussing passing bytes() strings to json.loads()
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54599
2014-10-25 01:00:55martin.pantersetnosy: + martin.panter
messages: + msg229972
2010-11-11 19:40:16r.david.murraysetstatus: open -> closed
stage: resolved
2010-11-11 16:53:22jfinkelssetresolution: not a bug
messages: + msg120961
2010-11-11 16:50:02jfinkelscreate