【发布时间】:2021-05-04 19:40:06
【问题描述】:
目前,我正在使用下面的代码来加载 JSON 文件。但是,我想加载 JSON 数据而不将文件保存到我的笔记本电脑。我尝试直接加载,但它给了我一个错误。
第一个代码:
url = "example.url"
response = requests.request("GET", url, headers=headers)
with open('save.json', 'wb') as outf:
outf.write(response.content)
file = open("save.json")
data = json.load(file)
代码尝试:
url = "example.url"
response = requests.request("GET", url, headers=headers)
data = json.load(response.content)
错误:
AttributeError: 'bytes' object has no attribute 'read'
【问题讨论】:
标签: python json python-requests