Andrew_Lvov
Andrew_Lvov

Reputation: 4668

No api proxy found for service "app_identity_service" when running GAE script

I'm trying to run a custom stript to upload static files to a bucket.

import os
import sys
sys.path.append("/tools/google_appengine")
from google.appengine.ext import vendor
from google.appengine.api import app_identity
vendor.add('../libraries')

import cloudstorage as gcs

STATIC_DIR = '../dashboard/dist'

def main():
    bucket_path = ''.join('/' + app_identity.get_default_gcs_bucket_name())

What I've been trying so far: - initialize stubs manuaIlly

def initialize_service_apis():
    from google.appengine.tools import dev_appserver

    from google.appengine.tools.dev_appserver_main import ParseArguments
    args, option_dict = ParseArguments(sys.argv) # Otherwise the option_dict isn't populated.
    dev_appserver.SetupStubs('local', **option_dict)

(taken from https://blairconrad.wordpress.com/2010/02/20/automated-testing-using-app-engine-service-apis-and-a-memcaching-memoizer/)

But this gives me import error when importing dev_appserver lib.

Is there any way to resolve the issue ? I need this script for an automatic deployment process.

Upvotes: 2

Views: 1462

Answers (2)

Dan Cornilescu
Dan Cornilescu

Reputation: 39834

The No api proxy found for service <blah> error messages typically indicate attempts to use GAE standard env infrastructure (packages under google.appengine in your case) inside standalone scripts, which is not OK. See GAE: AssertionError: No api proxy found for service "datastore_v3".

You have 2 options:

  • keep the code but make it execute inside a GAE app (as a request handler, for example), not as a standalone script
  • drop GAE libraries and switch to libraries designed to be used from standalone scrips. In your case you're looking for Cloud Storage Client Libraries. You may also need to adjust access control to the respective GAE app bucket.

Upvotes: 1

Chris
Chris

Reputation: 7298

I'm not familiar with dev_appserver.SetupStubs(), but I received this same error message while running unit tests in a testbed. In that environment, you have to explicitly enable stubs for any services you wish to test (see the docs).

In particular, initializing the app identity stub solved my problem:

from google.appengine.ext import testbed

t = testbed.Testbed()
t.init_app_identity_stub()

Upvotes: 0

Related Questions