【问题标题】:'socket' object has no attribute 'sendfile' while sending a file in flask + gunicorn + nginx + supervisor setup\'socket\' 对象在烧瓶 + gunicorn + nginx + 主管设置中发送文件时没有属性 \'sendfile\'
【发布时间】:2022-11-12 14:49:35
【问题描述】:

使用烧瓶,我试图通过使用 send_from_directory 函数单击 UI 中的按钮向用户发送文件。它曾经工作得很好。我想更改存储库,并且自从更改它以来,我无法再下载该文件。在查看主管日志时,我看到:

[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'

在同一个回购协议中,这在本地工作正常。但是当尝试使用 gunicorn + supervisor + nginx 设置在远程服务器中时,我收到了上述错误消息。我确实在应用程序日志文件中收到 200 Ok 响应。花了很多时间试图修复但没有成功。

此外,以前的 repo 和非工作的当前 repo 之间的工作应用程序之间的显着区别是 python 版本。上一个:python2.7,当前:python3.4

【问题讨论】:

    标签: python nginx flask supervisord


    【解决方案1】:

    对我来说,通常当一个脚本在本地工作但在托管它的一个(或多个)这些可能性时:

    • 文件的位置/路径不同
    • 旧版python
    • 旧版本的库

    【讨论】:

      【解决方案2】:

      将虚拟环境指向 Python 3.6 并升级包括 Flask 在内的所有相关库解决了该问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-30
        • 1970-01-01
        • 2014-09-02
        • 2022-11-13
        • 2019-09-20
        • 2021-10-15
        相关资源
        最近更新 更多