I get the following error when I try to access the 'data' variable from the endpoint '/'.
ValueError: [ValueError('dictionary update sequence element #0 has length 1; 2 is required'), TypeError('vars() argument must have __dict__ attribute')]
This is how FastAPI backend looks like:
from fastapi import FastAPI
app = FastAPI()
data = {}
@app.on_event("startup")
def startup_event():
data[1] = [...] ...(numpy array)
data[2] = [...] ...(numpy array)
return data
@app.get("/")
def home():
return {'Data': data}
When I launch the endpoint I see 'Internal Server Error'. Nothing would display at the endpoint '/'. However, if I add this line -> 'print(data)' just above the return in home function for endpoint '/', it does print the values stored in the data dictionary, as specified in the startup function. How can I fix the issue, so that the data variable becomes visible when accessing the '/' endpoint?