Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get large size JSON files using requests module in Python

I am trying to save a large JSON file into a variable using requests module but only part of the JSON is making it into the variable when using the following:

r = requests.get(url)

r.json()

I see there are ways to save it in chunks when writing to a file is there a way to do this when writing to a variable?

like image 281
jon Avatar asked Sep 03 '26 14:09

jon


1 Answers

According to the docs , using 'with' and setting stream to True should get you what you need.

with requests.get('http://httpbin.org/get', stream=True) as r:
    # Do things with the response here.
like image 184
SteveJ Avatar answered Sep 05 '26 04:09

SteveJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!