简体   繁体   中英

Gunicorn: Failed to find attribute 'app' in 'wsgi' when attempting to start flask server

Gunicorn fails to start flask server with the error: Failed to find attribute 'app' in 'wsgi'. .

The 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()

app.py

#!/usr/bin/python3
from flask import Flask
app = Flask(__name__)
...

Project structure:

(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

I checked ( Gunicorn can't find app when name changed from "application" ) but it doesn't relate to mine as I already use the application .

Any ideas what could be the problem?

Gunicorn is looking for app in wsgi so change

from app import app as application
if __name__ == "__main__":
    application.run()

to

from app import app as application
app = application

Then you can run do...which is what i am guessing you are doing

gunicorn <all the options here> wsgi:app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM