ImportError with Flask Application on Google App Engine: gcloud app deploy but "Service Unavailable"

Background - use AppEngine to deploy a Flask-app Vertex AI Widget (from Vertex Agent Builder with Datastore RAG on proprietary data).

Use App Engine Dashboard, default environment, and follow Google example (flask app): python-docs-samples/appengine/standard_python3/building-an-app/building-an-app-1 at main · GoogleClo...

After uploaded the files and ran locally and successfully via cloud shell, proceeded to gcloud app deploy, which went smoothly. Got "Service Unavailable" from target URL (project-ID.uc.r.appspot.com).

Recall two things I had to deviate from the guideline to complete App Engine deploy from Dashboard:

  1. Add / modify app.yaml (
    runtime: python38
    entrypoint: gunicorn -b :$PORT main:app)
  2. pip3 install -t lib -r requirements.txt (
    Flask==3.0.0)
    Successfully installed Flask-3.0.0 Jinja2-3.1.3 MarkupSafe-2.1.5 Werkzeug-3.0.2 blinker-1.7.0 click-8.1.7 itsdangerous-2.2.0

Out of curiosity, check 

pip3 freeze | grep -i flask >> requirements_check.txt (

Flask==1.1.4
Flask-PyMongo==2.3.0)
 
not Flask==3.0.0.
 
Additional calibration - repeat gcloud app deploy with Google example building-an-app-1 + steps 1 and 2 above, to no avail (result is "Service Unavailable").
 
Q: could "Service Unavailable" be attributable to incompatible Flask version in the environment?
 
I am new to GCP and appreciate any pointers to get over this hump.

 

Solved Solved
2 4 122
1 ACCEPTED SOLUTION

Since you added an entry point, gunicorn -b :$PORT main:app,  to your app.yaml file, you have to include the server software in your requirements.txt file i.e. you have to add 'gunicorn' to your requirements.txt file - see documentation which says 

>> If you have configured a Gunicorn web server entrypoint in the app.yaml file, you must also add gunicorn to your requirements.txt file.

Extra Information

1. While testing your app locally (running it locally), if you want to get a close approximation (not an exact match) of how your App will behave in production, then you should run your app with the dev_appserver.py tool.

2. Running with dev_appserver.py  will invoke your app.yaml file (and you would have seen the error about missing gunicorn). This in turn will test any entrypoints you have, static routes you have and the maximum size of each request

 

    ......NoCommandLine ......
https://nocommandline.com
        Analytics & GUI for 
App Engine & Datastore Emulator

View solution in original post

4 REPLIES 4

Since you added an entry point, gunicorn -b :$PORT main:app,  to your app.yaml file, you have to include the server software in your requirements.txt file i.e. you have to add 'gunicorn' to your requirements.txt file - see documentation which says 

>> If you have configured a Gunicorn web server entrypoint in the app.yaml file, you must also add gunicorn to your requirements.txt file.

Extra Information

1. While testing your app locally (running it locally), if you want to get a close approximation (not an exact match) of how your App will behave in production, then you should run your app with the dev_appserver.py tool.

2. Running with dev_appserver.py  will invoke your app.yaml file (and you would have seen the error about missing gunicorn). This in turn will test any entrypoints you have, static routes you have and the maximum size of each request

 

    ......NoCommandLine ......
https://nocommandline.com
        Analytics & GUI for 
App Engine & Datastore Emulator

@NoCommandLine, that does it. Many Thanks. 🤠

Flask==3.0.0
gunicorn==22.0.0
Werkzeug==3.0.1

requirements.txt works like  charm. It so happens doc in the Google Cloud Run Quickstart

Unless you have unique/detailed reasons to use specific versions, I'll advise removing the versions. Just have Flask, guicorn in your requirements.txt file

 

    ......NoCommandLine ......
https://nocommandline.com
        Analytics & GUI for 
App Engine & Datastore Emulator

Wouldn't it be safer to lock the versions of each package, in order to reduce the chance of issues arising when packages release new versions?

 

I know gunicorn has inadvertently introduced issues with new versions in the past.