We're in the migration process from webapp2 to the latest version of Django. We want to keep using legacy services like Appengine NDB for now before we move to the latest technologies.
For running the development environment locally I am using devappserver inside a docker environment because devappserver doesn't work with python3 according to Google.
My Google Cloud SDK version inside docker container is: 424.0.0
The server runs, but I keep getting this error whenever I try to access a View that uses some sort of legacy service:
google.appengine.runtime.apiproxy_errors.RPCFailedError: Attempted RPC call without active security ticket
The app.yaml (for deployment looks like this):
runtime: python38
instance_class: F2
app_engine_apis: 'True'
entrypoint: bash -c 'python3 manage.py migrate --settings=conf.settings.dev --noinput && gunicorn -b :$PORT main:app'
handlers:
- url: /static
static_dir: static/
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
builtins:
- deferred: on
env_variables:
DEBUG: 'False'
DB_HOST:
DB_PORT:
DB_NAME:
DB_USER:
DB_PASSWORD:
DJANGO_SETTINGS_MODULE: conf.settings.dev
main.py:
from conf.wsgi import application
from google.appengine.api import wrap_wsgi_app
app = wrap_wsgi_app(application, use_legacy_context_mode=True, use_deferred=False)
The django app works as expected when deployed to AppEngine Standard Environment. There is no error when running services inside the docker containers locally.
The package that I'm using for app engine bundled legacy service: Legacy Bundled Services
Example view:
from django.views import View
from django.http import JsonResponse
from google.appengine.api import memcache
class UserView(View):
def get(self, request):
memcache.set("Globe", "Jupiter")
return JsonResponse({'hello': memcache.get("Globe")})
I have tried these approaches and failed to resolve the error:
- Tried creating a appengine_config.py file but apparently that doesn't work
- Created a middleware to use AppEngine NDB using this middleware as a base (had to udpate it since latest django doesn't use MIDDLEWARE_CLASSES): google.appengine.ext.ndb.django_middleware.NdbDjangoMiddleware
- Performed authentication using gcloud auth activate-service-account --key-file=/app/conf/gcp_credentials.json and setting project id
- Configuring this env: GOOGLE_CLOUD_PROJECT
- Tried creating a separate container in docker using the old google cloud SDK i.e. 183.0.0 for using the datastore emulator