App Engine 数据存储区中的 GRPC 和类型导入错误

App Engine 数据存储区中的 GRPC 和类型导入错误

问题描述:

我成功地在 App 引擎中部署了我的应用程序.但是,当我尝试访问我的 API 时,我收到以下消息:

I deployed my application in App engine successfully. However, when I try to access my API, I receive the following message:

错误:服务器错误服务器遇到错误,无法完成您的请求.请在 30 秒后重试.

Error: Server Error The server encountered an error and could not complete your request. Please try again in 30 seconds.

我无法理解此问题的原因,因为它来自 Datastore API.有人可以帮我解决这个问题吗?

I'm unable to understand the cause of this issue, as it is coming from Datastore API. Can somebody please help me to troubleshoot this issue?

以下是所有相关信息.

回溯

当引用 URL 的根时

When referred to root of the URL

2018-03-27 08:08:45,090 <root> [ERROR]
2018-03-27 16:08:45.099 HKT
Traceback (most recent call last):
2018-03-27 16:08:45.099 HKT
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/6baee03590d046f1_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
2018-03-27 16:08:45.100 HKT
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
2018-03-27 16:08:45.100 HKT
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/6baee03590d046f1_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
2018-03-27 16:08:45.100 HKT
    handler, path, err = LoadObject(self._handler)
2018-03-27 16:08:45.100 HKT
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/6baee03590d046f1_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 96, in LoadObject
2018-03-27 16:08:45.100 HKT
    __import__(cumulative_path)
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/web/app.py", line 6, in <module>
2018-03-27 16:08:45.100 HKT
    from web.routes import ROUTES_BLUEPRINT
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/web/routes.py", line 7, in <module>
2018-03-27 16:08:45.100 HKT
    from metadata.repository.gcp_clouddatastore import GCPCloudDataStore
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/metadata/repository/gcp_clouddatastore.py", line 8, in <module>
2018-03-27 16:08:45.100 HKT
    from google.cloud import datastore
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore/__init__.py", line 60, in <module>
2018-03-27 16:08:45.100 HKT
    from google.cloud.datastore.batch import Batch
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore/batch.py", line 24, in <module>
2018-03-27 16:08:45.100 HKT
    from google.cloud.datastore import helpers
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore/helpers.py", line 29, in <module>
2018-03-27 16:08:45.100 HKT
    from google.cloud.datastore_v1.proto import datastore_pb2
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore_v1/__init__.py", line 18, in <module>
2018-03-27 16:08:45.100 HKT
    from google.cloud.datastore_v1.gapic import datastore_client
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore_v1/gapic/datastore_client.py", line 18, in <module>
2018-03-27 16:08:45.100 HKT
    import google.api_core.gapic_v1.client_info
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/api_core/gapic_v1/__init__.py", line 16, in <module>
2018-03-27 16:08:45.100 HKT
    from google.api_core.gapic_v1 import config
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/api_core/gapic_v1/config.py", line 23, in <module>
2018-03-27 16:08:45.100 HKT
    import grpc
2018-03-27 16:08:45.100 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/grpc/__init__.py", line 22, in <module>
2018-03-27 16:08:45.100 HKT
    from grpc._cython import cygrpc as _cygrpc
2018-03-27 16:08:45.100 HKT
ImportError: dynamic module does not define init function (initcygrpc)
2018-03-27 16:08:45.111 HKT
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.

访问除 root 之外的 API,向我展示了另一个回溯

Accessing API other then root, shows me another backtrace

2018-03-27 16:13:41.378 HKT
2018-03-27 08:13:41,377 <root> [ERROR] 
2018-03-27 16:13:41.378 HKT
Traceback (most recent call last):
2018-03-27 16:13:41.378 HKT
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/6baee03590d046f1_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
2018-03-27 16:13:41.378 HKT
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
2018-03-27 16:13:41.378 HKT
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/6baee03590d046f1_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
2018-03-27 16:13:41.378 HKT
    handler, path, err = LoadObject(self._handler)
2018-03-27 16:13:41.378 HKT
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/6baee03590d046f1_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 96, in LoadObject
2018-03-27 16:13:41.378 HKT
    __import__(cumulative_path)
2018-03-27 16:13:41.378 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/web/app.py", line 6, in <module>
2018-03-27 16:13:41.378 HKT
    from web.routes import ROUTES_BLUEPRINT
2018-03-27 16:13:41.378 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/web/routes.py", line 7, in <module>
2018-03-27 16:13:41.378 HKT
    from metadata.repository.gcp_clouddatastore import GCPCloudDataStore
2018-03-27 16:13:41.378 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/metadata/repository/gcp_clouddatastore.py", line 8, in <module>
2018-03-27 16:13:41.378 HKT
    from google.cloud import datastore
2018-03-27 16:13:41.378 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore/__init__.py", line 60, in <module>
2018-03-27 16:13:41.378 HKT
    from google.cloud.datastore.batch import Batch
2018-03-27 16:13:41.378 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore/batch.py", line 24, in <module>
2018-03-27 16:13:41.378 HKT
    from google.cloud.datastore import helpers
2018-03-27 16:13:41.378 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore/helpers.py", line 29, in <module>
2018-03-27 16:13:41.378 HKT
    from google.cloud.datastore_v1.proto import datastore_pb2
2018-03-27 16:13:41.378 HKT
  File "/base/data/home/apps/s~singapore-profile-dev2/20180327t160251.408595751204823647/lib/google/cloud/datastore_v1/__init__.py", line 17, in <module>
2018-03-27 16:13:41.378 HKT
    from google.cloud.datastore_v1 import types
2018-03-27 16:13:41.378 HKT
ImportError: cannot import name types

app.yaml 文件内容

app.yaml file contents

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: web.app.app
libraries:
- name: lxml
  version: latest

appengine_config.py 文件内容

appengine_config.py file contents

# appengine_config.py
from google.appengine.ext import vendor

# Add any libraries install in the "lib" folder.
vendor.add('lib')

您正在使用数据存储客户端库,但这在标准环境中不起作用.来自文档:

You are using the datastore client library, but this does not work in the standard environment. From the docs:

您不能在 App Engine 标准环境中将 Cloud Datastore 客户端库与 Python 应用程序一起使用.

You cannot use the Cloud Datastore client library with Python applications in the App Engine standard environment.

您需要按照推荐使用 ndb 包在文档中(我相信还有一个 REST API,但我从未使用过它).

You need to use the ndb package, as recommended in the docs (I believe there is also a REST API, but I've never used it).