Unable to return file stream in Python 3, uwsgi report error

Why can’t you stop buying 618?From the technical dimension to explore>>>

Questions

In the python 3 environment, when the web returns a file stream (for example, Django returns fileresponse), it will find that the client has not received any return, and the download will prompt a network error

Check the uwsgi log and find that the error is as follows:

io.UnsupportedOperation: fileno

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 156, in __call__
    response = environ['wsgi.file_wrapper'](response.file_to_stream)
SystemError: <built-in function uwsgi_sendfile> returned a result with an error set

Solution

Method 1

Add the -- WSGI disable file wrapper = true option to the uwsgi startup configuration, and then restart

https://github.com/unbit/uwsgi/issues/1126

https://uwsgi-docs.readthedocs.io/en/latest/Changelog-2.0.12.html#wsgi -disable-file-wrapper

Method 2

Use other ways to download, such as uploading to alicloud, qiniu, etc., and return to the download address to download

Similar Posts: