It's timeout while return a response with a large dictionary #11801
Unanswered
lanlanlaura
asked this question in
Questions
Replies: 1 comment 5 replies
-
Hi , i found the solution to your problem, first you need to install orjson because it load the josn file much faster compered to json. pip install orjson 2- use this code : from fastapi import FastAPI
import os
import json
import orjson
@app.get("/read-json")
async def read_json_file():
path = os.path.dirname(__file__)
file_path = os.path.join(path, "file.json")
with open(file_path, 'rb') as file:
content = file.read()
data = dict(orjson.loads(content))
return data Then send the request to the endpoint using Postman. I have already tried it with a file larger than 2MB, and the response was very quick. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
The test.json file size is around 2M, I convert it to dictionary, It's timeout, while FastAPI return a response. Thank you very much for your help.
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.110.1
Pydantic Version
2.6.4
Python Version
3.8.10
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions