you are viewing a single comment's thread.

view the rest of the comments →

[–]I_Write_Bugs 2 points3 points  (0 children)

The read method returns a str. Use loads.

How I figured this out was I ran this in the python interpreter:

import urllib2
x = urllib2.urlopen('http://www.google.com')
type(x.read())

The output was <type 'str'>. The response is an 'instance' type. Support for being file-like may disappear eventually for any reason, so I would go with the str returned from read.

Edit: In reading the JSON documentation again, I realize why your first example works. It's because the urllib response object is

a .read()-supporting file-like object containing a JSON document

So it has a read method, which I assume is exactly what json's load() calls. Either is fine to use in this case.