4

I am trying to deploy my app using Google App Engine. I have edited app.yaml to reflect the flexible environment and also gave all the app information. Below is the app.yaml file.

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
  python_version: 3

Once the deployment is in progress, I am getting the following error

[2018-08-24 06:57:14 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-08-24 06:57:14 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-08-24 06:57:14 +0000] [1] [INFO] Using worker: sync
[2018-08-24 06:57:14 +0000] [7] [INFO] Booting worker with pid: 7
App Deployed
Failed to find application: 'main'
[2018-08-24 06:57:14 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-08-24 06:57:14 +0000] [1] [INFO] Shutting down: Master
[2018-08-24 06:57:14 +0000] [1] [INFO] Reason: App failed to load.

Please note that App Deployed is the line in my print statement. It is getting executed. But the deployment is getting failed

Thank you in advance

Dustin Ingram
  • 15,737
  • 2
  • 40
  • 56
python_interest
  • 602
  • 1
  • 4
  • 18
  • Where is your main.py file located? It should be inside the folder where you are running `gcloud app deploy command`. – Yurci Aug 24 '18 at 13:53
  • Yes @Yurci .. It is inside the folder where I have app.yaml, requirements.txt and the python code as well (main.py) – python_interest Aug 27 '18 at 03:22

3 Answers3

1

In your app.yaml, you're starting gunicorn with gunicorn -b :$PORT main:app. This tells it to look for the object app in the file main.py

The error you're getting comes from gunicorn and occurs when you have a main.py file, but it does not have an app object in it.

You probably want to set up a Flask app as follows:

from flask import Flask

app = Flask(__name__)

See a full example app here: https://cloud.google.com/appengine/docs/flexible/python/quickstart#hello_world_code_review

Dustin Ingram
  • 15,737
  • 2
  • 40
  • 56
0

I have had the same issue.

Failed to find application: 'main'

The reason in my case was that I had a directory called also main in the root project directory.

drwxr-xr-x   2 user  staff    64 Nov 30 10:12 main
-rw-r--r--   1 user  staff  1178 Nov 29 20:58 main.py

I guess gunicorn got confused. The solution (worked for me): to rename main directory.

P.S. Just don't rename it to code directory. It will cause another issue with debugging in PyCharm. :)

Donald Duck
  • 137
  • 1
  • 8
0

My folder structure is looks llike this the main.py is not in the root directory how I can specify this in app.yaml file.

/app
 |__main.py
app.yaml
nipunravisara
  • 968
  • 1
  • 8
  • 18