0

I am trying to stream a file using Flask according to the answer given here: How do I stream a file using werkzeug?. The problem is I get the following error when werkzeug actually tries to stream the file:

ERROR:werkzeug:Error on request:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 319, in run_wsgi
    execute(self.server.app)
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 310, in execute
    for data in application_iter:
  File "/usr/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 0: invalid continuation byte

I am sending mpac files from my server and would like to avoid this decode/encode part entirely. Is there a way to avoid it in Flask? My code is below for reference

f = open(path_to_mpac)
resp = Response(f, status=200, direct_passthrough=True)
resp.headers["Content-Type"] = "application/octet-stream"
nbadami
  • 81
  • 2

0 Answers0