4

Following the example set in Izmailoff's blog post, I was able to send remote files from Flask to the user, but when I switched to Quart, I started receiving a TypeError: 'function' object is not iterable error.

The code is almost the exact same as on the blog, and I've tried using await to no avail, as it errored out with object Response can't be used in 'await' expression.

My code is as follows, with raw_url being the direct-access URL:

req = requests.get(raw_url, stream=True)
return Response(stream_with_context(req.iter_content()), content_type=req.headers['content-type'])
  • For more context, a stack trace can be found here: https://pastebin.com/pib4dkAy – George Tsatsis Jul 14 '20 at 13:48
  • I've found a workaround for now, but I'd be interested if someone has an explanation, or an answer to add to this. // Removing `stream_with_context()` and just leaving the response with the request content iterator seems to have worked. – George Tsatsis Jul 14 '20 at 16:02

1 Answers1

1

The error

for data in iterable:  # type: ignore

TypeError: 'function' object is not iterable

is telling you that the stream_with_context() is not returning an object of type iterable. You can indeed inspect that by printing the output of that function and see what it returns.

My only guess would be that the values returned by the iter_content() of the req module may be different from the one on the blog

req.iter_content()

and hence the error. I am also inclined to think that this could also be caused by difference in flask/python versions.

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35