google-app-enginegoogle-cloud-platformgoogle-cloud-datastoregoogle-app-engine-python

'No api proxy found for service "%s"' % service AssertionError: No api proxy found for service "datastore_v3"


I'm using Google App Engine with Datastore.

Here is my model class project_name/model/quiz_models.py

from google.appengine.ext import db


class Quiz(db.Model):
    quiz_id = db.StringProperty()
    post_id = db.StringProperty()
    creator_id = db.StringProperty()
    timestamp = db.DateTimeProperty()
    quiz_title = db.StringProperty()

main.py file

@app.route('/insert_db')
def run_quickstart():
    quiz = Quiz(post_id=data['post_id'],
                quiz_id='123',
                quiz_info='test info',
                creator_id=data['creator_id'],
                timestamp=datetime.datetime.now(),
                quiz_title='Test title')
    quiz.put()

When do I make get request to /insert_db URL I'm getting this error

File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/appengine/api/apiproxy_stub_map.py", line 69, in CreateRPC      
assert stub, 'No api proxy found for service "%s"' % service  AssertionError: No api proxy found for service "datastore_v3"

But this sample snippets provided by google works fine

@app.route('/insert_db')
def run_quickstart():
    # [START datastore_quickstart]
    # Imports the Google Cloud client library

    # Instantiates a client
    datastore_client = datastore.Client()

    # The kind for the new entity
    kind = "Tasker"
    # The name/ID for the new entity
    name = "sampletask1aa"
    # The Cloud Datastore key for the new entity
    task_key = datastore_client.key(kind, name)

    # Prepares the new entity
    task = datastore.Entity(key=task_key)
    task.update(
        {
            "category": "Personal",
            "done": False,
            "priority": 4,
            "description": "Cloud Datastore",
        }
    )

    # Saves the entity
    datastore_client.put(task)

Solution

  • There are many ways of interacting with datastore from GAE. The many options make it quite confusing, but I'll try to point you in the right direction.

    Your code is using very old datastore access techniques as indicated by this line:

    from google.appengine.ext import db
    

    This was the original first generation GAE with Python 2. I suspect that it isn't possible to use this with Python 3.

    From your code, it looks like you would like to use second generation GAE with Python 3 (this is good since the older stuff is being phased out). You have two main datastore options:

    1. Use the google-cloud-datastore Python client. This is what the working code sample above is using.
    2. Use the google-cloud-ndb Python client. This is closer to the old db library in your code.

    If you are starting a new project, then the first choice is better. If you are migrating a Python 2 project, then the second choice might be better.