Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 369
Omar Abdelrazik Avatar asked Jul 08 '20 16:07

Omar Abdelrazik


Video Answer


1 Answers

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
like image 60
flexxxit Avatar answered Nov 14 '22 21:11

flexxxit