I'm trying to convert a string, generated from an http request with urllib3.
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
data = json.load(data)
File "C:\Python27\Lib\json\__init__.py", line 286, in load
return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'
>>> import urllib3
>>> import json
>>> request = #urllib3.request(method, url, fields=parameters)
>>> data = request.data
Now... When trying the following, I get that error...
>>> json.load(data) # generates the error
>>> json.load(request.read()) # generates the error
Running type(data)
and type(data.read())
both return <type 'str'>
data = '{"subscriber":"0"}}\n'
type(data.read())
shouldn't work ifdata
is a string. – Sprawltype(data.read())
is guaranteed to raise the exact same exception asjson.load(data)
. I think he meanttype(request.read())
, which will successfully return thestr
type. – Joly