The main documentation pages claim that it does: "The Python 2.7 runtime supports the WSGI standard and the CGI standard for backwards compatibility."
This must then be a very obvious problem, but I can't figure it out. I'm new to Google App Engine and am trying to use it to run an old Python CGI app. I've installed the SDK on my Linux system and have an app.yaml file that says this:
application: your-app-id
version: 3
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /.*
script: members.py
The script and necessary files are in a folder called sms-gae inside the google_appengine folder. When I run
./dev_appserver.py sms-gae/
the program runs when I access localhost:8080, but the output appears on the terminal console instead of in the browser. Nothing is output to the browser. The same application runs fine in a normal web server CGI environment.
According to the main GAE documentation, "App Engine collects all of the data the request handler script writes to the standard output stream, then waits for the script to return. When the handler completes, all of the output data is sent to the user."
From what I can see of the GAE Development Environment documentation - and in more detail here - I've set it up correctly. Documentation on using CGI scripts is rather sparse, and can't find anything on this problem on the Internet as well.
The output is as follows:
INFO 2013-10-10 23:05:55,535 sdk_update_checker.py:245] Checking for updates to the SDK.
INFO 2013-10-10 23:05:56,838 sdk_update_checker.py:289] This SDK release is newer than the advertised release.
INFO 2013-10-10 23:05:57,181 api_server.py:138] Starting API server at: http://localhost:49954
INFO 2013-10-10 23:05:57,225 dispatcher.py:168] Starting module "default" running at: http://localhost:8080
INFO 2013-10-10 23:05:57,241 admin_server.py:117] Starting admin server at: http://localhost:8000
Content-Type: text/html; charset= utf-8
[The Content-Type line comes from my script and is followed by its output]
INFO 2013-10-10 23:06:05,227 members.py:73] No userid or password supplied.
INFO 2013-10-10 23:06:05,262 module.py:599] default: "GET / HTTP/1.1" 200 -
After research and some of the answers here (since deleted for some reason), it seems that GAE does not in fact support CGI (or at least not vanilla "normal" CGI). What they seem to mean is that GAE accepts WSGI code that is run with a CGI adaptor (see the discussion here for an example).
However, it is relatively easy to convert a CGI app to WSGI in a crude way, using the trick given here. If you add this code to the bottom of the app, it will do it, assuming the main code is run from the function
mainfunc
and it responds to get requests (otherwise a similarpost
method can be defined):and then redirect app.yaml to point at "members.app" (in my case) as the handler for all URLs.