【问题标题】:'No api proxy found for service "%s"' % service AssertionError: No api proxy found for service "datastore_v3"'未找到服务“%s”的 api 代理' % service AssertionError: 未找到服务“datastore_v3”的 api 代理
【发布时间】:2021-11-29 12:59:05
【问题描述】:

我正在使用 Google App EngineDatastore

这是我的模型类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文件

@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()

我何时向/insert_db URL 发出获取请求时收到此错误

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"

但是 google 提供的这个示例 sn-ps 工作正常

@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)

【问题讨论】:

    标签: google-app-engine google-cloud-platform google-cloud-datastore google-app-engine-python


    【解决方案1】:

    有多种方式可以与 GAE 中的数据存储进行交互。许多选项让人很困惑,但我会尽力为您指明正确的方向。

    您的代码正在使用非常古老的数据存储访问技术,如下行所示:

    from google.appengine.ext import db
    

    这是最初使用 Python 2 的第一代 GAE。我怀疑它无法在 Python 3 中使用。

    从您的代码来看,您似乎希望将第二代 GAE 与 Python 3 一起使用(这很好,因为旧的东西正在被逐步淘汰)。您有两个主要的数据存储选项:

    1. 使用the google-cloud-datastore Python client。这就是上面的工作代码示例所使用的。
    2. 使用the google-cloud-ndb Python client。这更接近代码中的旧 db 库。

    如果您正在开始一个新项目,那么首选是更好的选择。如果您正在迁移 Python 2 项目,那么第二个选择可能会更好。

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      • 2016-01-14
      相关资源
      最近更新 更多