I have a json file that I provide via flask, and I'd like to parse it from a requests object, but I can't get the full data back. I get a broken json file. What I get is about one third of the way through the file to the end.
I get different answers whether I use r.json()
or json.loads(r.text)
from the simple get request:
r = requests.get("url/api")
If I stream it manually, I can see the start of the file
r= requests.get("url/api", stream=True)
r.raw.read(1000).decode('utf-8')
And I successfully save down the file as here how to parse big requests object, but the problem persists when I try to then upload the file using json.load(local_filename)
The shape of my json file is:
[{"key1":"value1_1", "key2":"value2_1"},{"key1":"value1_2", "key2":"value2_2"}.......]
This is how I provide the json from flask
@app.route('/api', methods=['GET'])
def provide_json():
with open('record_file.json') as f:
record_file = json.load(f)
return json.dumps(record_file)
I've checked that my json file is valid, and I'm also assuming that my flask code with throw an exception is I wasn't delivering a valid json file because I've used json.dumps
. Is that right? I've also tried wrapping the json file in flask with return json.dumps({"data_file":record_file})
but it doesn't change the problem.