skip to Main Content

Using flask, I’m trying to send a file to the user on clicking a button in UI using send_from_directory function. It used to work fine. I wanted to change the repo and since changing it, I’m no more able to download the file. On looking at the supervisor log, I see this:

[9617] [ERROR] Error handling request
Traceback (most recent call last):
  File "path_to_file/venv/lib/python3.4/site-packages/gunicorn/workers/sync.py", line 182, in handle_request
    resp.write_file(respiter)
  File "path_to_file/venv/lib/python3.4/site-packages/gunicorn/http/wsgi.py", line 385, in write_file
    if not self.sendfile(respiter):
  File "path_to_file/venv/lib/python3.4/site-packages/gunicorn/http/wsgi.py", line 375, in sendfile
    self.sock.sendfile(respiter.filelike, count=nbytes)
AttributeError: 'socket' object has no attribute 'sendfile'

In the same repo, this works fine locally. But when trying in remote server using the gunicorn + supervisor + nginx setup, I get the above error message. I do get 200 Ok response in the application log file. Spent a lot of time trying to fix but without success.

Also, the notable difference between the working app between the previous repo and the non-working current repo is the python version. Previous: python2.7, Current: python3.4

2

Answers


  1. Chosen as BEST ANSWER

    Pointing the virtual env to Python 3.6 and upgrading all the relevant libraries including Flask resolved the issue.


  2. For me, usually when a script works locally but not when hosted its one (or more) of these possibilities:

    • Location / path to the files is different
    • older version of python
    • older version of the library
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search