14

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?

2
  • What is your shell command to run gunicorn? It's important so as to debug your error. For my case it is the param gunicorn your.wsgi:yourappname where you put :yourappname to be the app instance you create in your code
    – Nam G VU
    Jul 6, 2021 at 2:43
  • Your gunicorn command to run should be gunicorn wsgi:app instead of gunicorn wsgi I guess - the later one will use default instance name as application
    – Nam G VU
    Jul 6, 2021 at 2:44

1 Answer 1

16

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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.