Google App Engine Python: Error in yaml config file when deploying

The earlier answer from @Omair, while correct, is only part of the story. The OP's original question utilizes an App Engine first-generation ("Gen1") runtime app's app.yaml configuration file where the routing happens, requiring the script: directive in handlers:. While that's a perfectly valid app.yaml for a Gen1 (go111, python [2.5], python27, php55) app, it won't work for next generation ("Gen2") apps.

NOTE: Python 2 is only supported by App Engine Gen1 whereas Python 3 is only supported by App Engine Gen2 (Standard or Flex), so if you migrate from Python 2 to 3, you're also porting from Gen1 to Gen2 and need to keep in mind these differences as well. (Unfortunately, this means migrating from webapp2 to a web framework that handles routing, i.e., Django, Flask, etc.)

App Engine Gen2 requires routing to be done by your framework. As a result, all Gen1 app.yaml files need to be updated. Use of handlers: for your routes must be either removed or changed to auto (because it's done by your web framework now). If you have specific app startup instructions, you can provide an entrypoint: directive; check out these examples.

Both handlers: and entrypoint: are optional. If all script handlers are auto, you don't need handlers: unless your app is serving static files like client-side JS, CSS, HTML, images, etc., and entrypoint: is optional because if you don't specify a server, gunicorn is selected (and started) by default. Basically if you take all the defaults and don't serve static files, you can reduce app.yaml down to 1 line, like this one. That sample is from a repo I'm working on to help developers upgrade Python 2 App Engine apps to Python 3 who need more help than what's available in the official migration guide.


I got this error when deploying a flask app with a blueprint structure. The solution is to have main.py file in the same directory as app.yaml file. In the main.py file, import the app object e.g from app import app (here the first 'app' is the folder containing an init file where the flask app instance is created). After doing this, setting script to auto should work fine.


As per the AppEngine documentation for Python 3.7,

The only accepted value for the script element is auto

Below is a sample entry from the documentation:

handlers:
- url: /images
  static_dir: static/images

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto