JSON对象必须是str、bytes或bytearray,而不是method

2024-04-24 06:32:26 发布

您现在位置:Python中文网/ 问答频道 /正文

response = requests.get(api).json
print(type(response))
data = json.loads(response)

我得到了<class method>和错误: JSON object must be str, bytes or bytearray, not method

有人能帮忙把它转换成dict吗


Tags: apijsondatagetobjectresponsetype错误
1条回答
网友
1楼 · 发布于 2024-04-24 06:32:26

写入response = requests.get(api).json时,将json方法本身存储在response中,而不是调用该方法并将该方法调用的结果存储在response

如果将其更改为requests.get(api).json(),并在末尾加上括号,则将调用该方法而不是仅引用它,并将结果存储在response

相关问题 更多 >