Say that my function "search()" fetches some content in the mongodb and returns the generator.
My flask view function looks like this
@app.route("search/")
def search_page():
generator = search()
return Response(generator)
But if I do that, I get this error:
Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 180, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 171, in execute
write(data)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 151, in write
assert type(data) is bytes, 'applications must write bytes'
AssertionError: applications must write bytes
The generator itself would yield several json values. I could always use the generator to construct a list and return the list, but I would like to avoid doing that.
There are two problems in your code.
Here is the example:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With