Im trying to deploy a web app using flask to heroku using gunicorn. I've been trying for roughly 2 days but with no luck. I currently have this error:
Failed to find attribute 'app' in '__main__'.
I know the error is saying that it couldn't find app
in __main__.py
but I don't know why it couldn't find it as app
is in __main__.py
, as you can see below.
'Procfile'
web: gunicorn __main__:app
'__main__.py' (first 9 lines and last 2 lines)
from flask import Flask, render_template, redirect, request, session, g
import random
import requests
import mysql.connector
from oauth import Oauth
from oauth2 import Oauth2
app = Flask(__name__)
# 200 removed lines of flask code that powers the backend goes here
if __name__ == "__main__":
app.run()
This is what my directly looks like if it helps:
web
-static
-templates
-__main__.py
-oauth.py
-oauth2.py
-Procfile
-requirements.txt
Here is the full error logs from heroku
2021-01-27T12:55:26.211031+00:00 app[web.1]: [2021-01-27 12:55:26 +0000] [9] [INFO] Booting worker with pid: 9
2021-01-27T12:55:26.213834+00:00 app[web.1]: Failed to find attribute 'app' in '__main__'.
2021-01-27T12:55:26.214015+00:00 app[web.1]: [2021-01-27 12:55:26 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-01-27T12:55:26.223266+00:00 app[web.1]: [2021-01-27 12:55:26 +0000] [10] [INFO] Booting worker with pid: 10
2021-01-27T12:55:26.226404+00:00 app[web.1]: Failed to find attribute 'app' in '__main__'.
2021-01-27T12:55:26.226731+00:00 app[web.1]: [2021-01-27 12:55:26 +0000] [10] [INFO] Worker exiting (pid: 10)
2021-01-27T12:55:26.359501+00:00 app[web.1]: [2021-01-27 12:55:26 +0000] [4] [INFO] Shutting down: Master
2021-01-27T12:55:26.359767+00:00 app[web.1]: [2021-01-27 12:55:26 +0000] [4] [INFO] Reason: App failed to load.
2021-01-27T12:55:26.447672+00:00 heroku[web.1]: Process exited with status 4
2021-01-27T12:55:26.511220+00:00 heroku[web.1]: State changed from starting to crashed
It runs fine without gunicorn on localhost on my laptop but not hosted on heroku with gunicorn.
question from:
https://stackoverflow.com/questions/65919888/failed-to-find-attribute-app-in-main 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…