hassansuhaib
hassansuhaib

Reputation: 297

Devappserver: Attempted RPC call without active security ticket

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

Error log: docker error logs

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:

Upvotes: 1

Views: 891

Answers (3)

Rimu Atkinson
Rimu Atkinson

Reputation: 777

I was having the same problem and in my case it was caused by accessing the website through the wrong port.

When running dev_appserver.py there are a variety of console messages that scroll by while it's starting. At the end it'll print something like:

                                                                                               
INFO     2023-04-13 00:44:31,949 dispatcher.py:276] Starting module "default" running at: http://0.0.0.0:8080
INFO     2023-04-13 00:44:31,950 admin_server.py:70] Starting admin server at: http://localhost:8000
INFO     2023-04-13 00:44:32,955 instance.py:561] Cannot decide GOOGLE_CLOUD_PROJECT, using "test" as a fake value
[2023-04-13 12:44:33 +1200] [17518] [INFO] Starting gunicorn 20.1.0
[2023-04-13 12:44:33 +1200] [17518] [INFO] Listening at: http://0.0.0.0:42919 (17518)
[2023-04-13 12:44:33 +1200] [17518] [INFO] Using worker: sync
[2023-04-13 12:44:33 +1200] [17520] [INFO] Booting worker with pid: 17520

There are a few different port numbers there. 8080, 8000, 42919. I was accessing the site at http://0.0.0.0:42919 and it seems to work - simple pages load ok. But as soon as memcache or datastore functions are called the error message about RPC call is displayed.

Use http://0.0.0.0:8080 and everything works properly.

Upvotes: 1

NoCommandLine
NoCommandLine

Reputation: 6263

devappserver doesn't work with python3 according to Google.

From the above, I assume you're running on Windows. If so, we have a patch that swaps out Gunicorn (since by default it doesn't work on windows and is what dev_appserver.py uses) for Waitress when you run with dev_appserver.py on your local environment (see this post on Google Cloud Community)

You can then run your App locally without having to use docker containers and it works with the Bundled APIs.

Upvotes: 1

Roopa M
Roopa M

Reputation: 3009

As mentioned in the public document you should have Python 2 interpreter of version 2.7.12 or newer, irrespective of languages used in your app to run dev_appserver tools.

Important: To run the dev_appserver.py tool, you must have a Python 2 interpreter of version 2.7.12 or newer installed on your machine (even if your app is written in another language or version , including Python 3).

The dev_appserver tool does not support development of Python 3 apps on Windows.

You have to run the following command to ensure the Python 2 interpreter is used.

dev_appserver.py --runtime_python_path="python27=/usr/bin/python2.7,python3=/usr/bin/python3" [PATH_TO_YOUR_APP]

Upvotes: 0

Related Questions