gpt4 book ai didi

python - 如何使用 Python 中的 requests 模块获取大尺寸 JSON 文件

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:43 24 4
gpt4 key购买 nike

我正在尝试使用 requests 模块将大型 JSON 文件保存到变量中,但只有部分 JSON 将其放入使用以下内容时的变量:

r = requests.get(url)

r.json()

我看到在写入文件时有一些方法可以将其保存为 block ,在写入变量时有没有办法做到这一点?

最佳答案

根据docs ,使用“with”并将stream设置为True应该可以满足您的需要。

with requests.get('http://httpbin.org/get', stream=True) as r:
# Do things with the response here.

关于python - 如何使用 Python 中的 requests 模块获取大尺寸 JSON 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47586741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com