Migrated Blog to AppEngine Python 3

This site is now running on AppEngine Python 3 runtime.

For reference, see AppEngine Migrating to Python 3 runtime.

Thankfully, AppEngine standard environment allows us to access many of legacy bundled services and APIs in the Python 3 runtime.

Since I am lazy, I try to make as little change as possible. That includes using back the old webapp2 framework even though Google documentation says it is not supported in Python 3. The only issue I encounter is that webapp2.Response cannot write a binary bytes object, it will raise an error. There is a solution for this issue.

The requirements.txt file has 2 library dependencies, they are appengine-python-standard and webapp2. The AppEngine runtime will automatically install those listed in requirements.txt

requirements.txt

appengine-python-standard>=1.0.0
webapp2==3.0.0b1


To use legacy services, add "app_engine_apis: true" to the app.yaml config file. Other app.yaml changes includes script handlers.

In main.py , we need to call wrap_wsgi_app to use AppEngine WSGI middleware so as to access legacy bundled services and APIs. In my case, the code also use the deferred API.

main.py

from google.appengine.api import wrap_wsgi_app
app = wrap_wsgi_app(webapp2.WSGIApplication(routes), use_deferred=True)



I run into the following error when deploying the app. It appears there is some issue with the default service account.

gcloud app deploy --version 5 --no-promote
 
ERROR: (gcloud.app.deploy) PERMISSION_DENIED: The version cannot run because
it is unable to generate an access token for the target service account timeless-sky@appspot.gserviceaccount.com.
Please check that your project has the App Engine Standard Service Agent role
following https://cloud.google.com/appengine/docs/standard/go/service-agent.


After I create a new service account with the Editor role. It deploys successfully with the new service account.

gcloud app deploy --version 5 --service-account xxxx@timeless--sky.iam.gserviceaccount.com --no-promote


Comments

blog comments powered by Disqus

Categories