I have a Flask api and I would like to make a route which send several types of data continuously with a stream. Here is my current function definition (with placeholder data) :
@app.route("/heterogeneous stream")
def stream():
def generator():
yield [0,1,2,3,4]
yield {"a":10, "b":20, "c":30}
yield "value"
return app.response_class(generator())
However I get the following error :
AssertionError: applications must write bytes
So i have two questions :
Is it mandatory to have the data encoded as bytes when using streams, and then parsing it when receiving it ?
And if no, how to send data of different types in one singular stream ?
Thanks