0

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

Alexis Pister
  • 410
  • 2
  • 12
  • "how to send data of different types" -- You don't. How will your client know how to decode what you send? – erip Oct 15 '21 at 11:46

0 Answers0