GRPC and types import error in App Engine Datastore

[亡魂溺海] 提交于 2019-12-29 01:44:11

问题


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

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

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?

Below is all the relevant information.

Backtraces

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.

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 file contents

runtime: python27
api_version: 1
threadsafe: true

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

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

回答1:


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

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

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




回答2:


The first traceback appears to suggest that grpc is somehow involved, and that's a problem. According to comments on issue 149 grpc is not yet supported on GAE standard environment.

But since you're on the GAE standard environment you should really use the recommended, GAE-optimized (and more feature-rich) NDB Client Library to access the datastore, not the generic google.cloud.datastore one (which might indeed include features not meeting the standard env sandbox restrictions).



来源:https://stackoverflow.com/questions/49527475/grpc-and-types-import-error-in-app-engine-datastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!