簡體   English   中英

在 Gunicorn 上運行的 Flask-SocketIO 應用程序拋出 TypeError

[英]Flask-SocketIO app running on Gunicorn throws TypeError

我有一個可用的 Flask-SocketIO 服務器,但它不能與 Gunicorn 一起使用。 服務器的相關部分如下所示:

def main(env, resp):

    app = Flask(__name__,
                static_url_path='',
                static_folder='dist',
                template_folder='dist')

    socketio = SocketIO(app)

    @app.route('/')
    def home():
        return app.send_static_file('index.html')

    # socketio.run(app, host='0.0.0.0', port=8000) I comment this out when using Gunicorn because otherwise it tries to run the process twice and throws an error.

我使用eventlet和運行,如燒瓶SocketIO文檔中描述的下列命令在這里

gunicorn --worker-class eventlet -b 0.0.0.0:8000 -w 1 index:main

gunicorn 進程開始正常,但是當我導航到該頁面時,我收到以下服務器錯誤:

Error handling request /
Traceback (most recent call last):
  File "/home/myusername/.local/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 55, in handle
    self.handle_request(listener_name, req, client, addr)
  File "/home/myusername/.local/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 113, in handle_request
    for item in respiter:
TypeError: 'NoneType' object is not iterable

我找不到有關此錯誤的任何信息,希望有任何想法。

我不得不從 main() 返回 app。 main 中的附加參數是不必要的。 我還添加了一個 wsgi 文件:

from index import main

if __name__ == '__main__':
    main()
else:
    gmain = main()

然后使用該文件運行 gunicorn: gunicorn -k eventlet -b 0.0.0.0:8000 -w 1 wsgi:gmain並且它起作用了。 Seleniumwire 拋出錯誤,但這超出了本問題的范圍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM