Gunicorn:尝试启动 Flask 服务器时无法在“wsgi”中找到属性“app”

Oma*_*ham 6 python flask gunicorn

Gunicorn 无法启动 Flask 服务器,错误为:Failed to find attribute 'app' in 'wsgi'.。

wsgi.py

#!/usr/bin/python3
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/root/customer-account-automation/")

from app import app as application
if __name__ == "__main__":
    application.run()
Run Code Online (Sandbox Code Playgroud)

应用程序

#!/usr/bin/python3
from flask import Flask
app = Flask(__name__)
...
Run Code Online (Sandbox Code Playgroud)

项目结构:

(customer-account-automation) root@jsd-user-management:~/customer-account-automation# tree
.
??? Pipfile
??? Pipfile.lock
??? README.md
??? __pycache__
?   ??? app.cpython-37.pyc
?   ??? wsgi.cpython-37.pyc
??? app.py
??? customerAccountMgmt.py
??? get-pip.py
??? static
?   ??? app.js
?   ??? bulma.min.css
?   ??? highlight.min.css
?   ??? highlight.min.js
?   ??? styles.css
??? templates
?   ??? 404.html
?   ??? base.html
?   ??? change_password.html
?   ??? create_user.html
?   ??? deactivate_user.html
?   ??? login.html
??? wsgi.py
Run Code Online (Sandbox Code Playgroud)

我检查了(当名称从“应用程序”更改时 Gunicorn 找不到应用程序)但它与我的无关,因为我已经使用了application.

任何想法可能是什么问题?

fle*_*xit 6

Gunicorn 正在 wsgi 中寻找应用程序所以改变

from app import app as application
if __name__ == "__main__":
    application.run()
Run Code Online (Sandbox Code Playgroud)

到

from app import app as application
app = application
Run Code Online (Sandbox Code Playgroud)

然后你可以跑做...这就是我猜你在做什么

gunicorn <all the options here> wsgi:app
Run Code Online (Sandbox Code Playgroud)