Gunicorn 内部服务器错误

Pav*_*dhu 1 python flask gunicorn

我正在使用 Flask 应用程序设置 Gunicorn。我有以下文件结构:

Flask/
  run.py
  myapp/
    __init__.py
    views/
      homepage/
        __init__.py
        homepage.py
      login/
        __init__.py
        login.py
      blog/
        __init__.py
        blog.py
Run Code Online (Sandbox Code Playgroud)

run.py文件导入应用程序实例Flask/myapp/__init__.py并运行它,如下所示:

from myapp import app
def run():
  app.run()
Run Code Online (Sandbox Code Playgroud)

我使用命令行运行gunicorn run:run并启动网站。我访问该网站并收到内部服务器错误,说明如下:

[2015-09-14 19:00:41 +0100] [35529] [ERROR] Error handling request
Traceback (most recent call last):
  File "/Users/pavsidhu/.virtualenvs/environment/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
    self.handle_request(listener, req, client, addr)
  File "/Users/pavsidhu/.virtualenvs/environment/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 171, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
TypeError: run() takes no arguments (2 given)
Run Code Online (Sandbox Code Playgroud)

有什么问题吗?谢谢。

Tho*_*zco 5

您应该将WSGI 可调用传递gunicorn给. 事实证明app是之一,但你的run功能不是。

因此,不要运行gunicorn run:run,而是运行:gunicorn run:app