我正在尝试将一个由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
现在...当我尝试以下操作时,会出现该错误...
>>> json.load(data) # generates the error
>>> json.load(request.read()) # generates the error
运行 type(data)
和 type(data.read())
都会返回 <type 'str'>
data = '{"subscriber":"0"}}\n'
data
是字符串,type(data.read())
不应该起作用。 - Blendertype(data.read())
肯定会引发与json.load(data)
完全相同的异常。我想他的意思是type(request.read())
,它将成功地返回str
类型。 - abarnert