我正在尝试用 python 显示 http 请求的内容,我试过了
page= requests.request(method="get",url=url, params= parameters)
j_results=json.loads(page.text)
print (page)
但是我明白了:
ValueError Traceback (most recent call last)
<ipython-input-42-9f7940edb2de> in <module>()
13 page= requests.request(method="get",url=url, params= parameters)
14
---> 15 j_results=json.loads(page.text)
16 print (page.text)
17
C:\Users\sony\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
316 parse_int is None and parse_float is None and
317 parse_constant is None and object_pairs_hook is None and not kw):
--> 318 return _default_decoder.decode(s)
319 if cls is None:
320 cls = JSONDecoder
我正在使用 Python 3。
最佳答案
您的回溯显示的内容与您发布的代码不同。
# Your code snippet
j_results=json.load(page.text)
# Your traceback
j_results=json.load(page)
# You should be using the `loads` function (which loads from a string)
j_result = json.loads(page.text)
更改您的代码以匹配您在代码段中发布的内容。或者,如果您知道响应已经是 JSON,则可以使用
j_result = page.json()
关于python - 属性错误 : 'Response' object has no attribute 'read' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33036294/