使用 grpc 和 cloud-datastore 时如何修复 App Engine Flex 中的 AttributeError?
Posted
技术标签:
【中文标题】使用 grpc 和 cloud-datastore 时如何修复 App Engine Flex 中的 AttributeError?【英文标题】:How to fix AttributeError in App Engine Flex when using grpc and cloud-datastore? 【发布时间】:2020-09-25 03:31:16 【问题描述】:当我使用 Google App Engine Flex 部署 python3 应用程序时,我收到以下错误:
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/vmagent/app/run.py", line 8, in <module>
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
File "/home/vmagent/app/application/__init__.py", line 43, in create_app
from .main import main as main_blueprint
File "/home/vmagent/app/application/main/__init__.py", line 5, in <module>
from . import cron_jobs, views
File "/home/vmagent/app/application/main/cron_jobs.py", line 4, in <module>
from google.cloud import datastore
File "/env/lib/python3.6/site-packages/google/cloud/datastore/__init__.py", line 60, in <module>
from google.cloud.datastore.batch import Batch
File "/env/lib/python3.6/site-packages/google/cloud/datastore/batch.py", line 24, in <module>
from google.cloud.datastore import helpers
File "/env/lib/python3.6/site-packages/google/cloud/datastore/helpers.py", line 29, in <module>
from google.cloud.datastore_v1.proto import datastore_pb2
File "/env/lib/python3.6/site-packages/google/cloud/datastore_v1/__init__.py", line 18, in <module>
from google.cloud.datastore_v1.gapic import datastore_client
File "/env/lib/python3.6/site-packages/google/cloud/datastore_v1/gapic/datastore_client.py", line 18, in <module>
import google.api_core.gapic_v1.client_info
File "/env/lib/python3.6/site-packages/google/api_core/gapic_v1/__init__.py", line 26, in <module>
from google.api_core.gapic_v1 import method_async # noqa: F401
File "/env/lib/python3.6/site-packages/google/api_core/gapic_v1/method_async.py", line 20, in <module>
from google.api_core import general_helpers, grpc_helpers_async
File "/env/lib/python3.6/site-packages/google/api_core/grpc_helpers_async.py", line 145, in <module>
class _WrappedStreamUnaryCall(_WrappedUnaryResponseMixin, _WrappedStreamRequestMixin, aio.StreamUnaryCall):
AttributeError: module 'grpc.experimental.aio' has no attribute 'StreamUnaryCall'
我的requirements.txt
文件包括以下内容:
google-cloud-datastore==1.12.0
grpcio==1.27.2
我使用 grpcio 版本 1.27.2 而不是最新的 1.29.0 的原因是因为显示的信息 here
有人可以帮忙吗?
【问题讨论】:
另外,我的 app.yaml 中有以下环境变量:GOOGLE_CLOUD_DISABLE_GRPC: True 【参考方案1】:我刚刚遇到了同样的问题,所以这可能会对你有所帮助。我注意到google-api-core
也是一个依赖项,它最近已更新(特别是围绕grpc_helpers_async),所以我只是将它固定到版本 1.17.0 并解决了这个问题。只需将此添加到您的要求中:
google-api-core==1.17.0
【讨论】:
在他们的 repo 上打开了一个问题:github.com/googleapis/python-api-core/issues/47以上是关于使用 grpc 和 cloud-datastore 时如何修复 App Engine Flex 中的 AttributeError?的主要内容,如果未能解决你的问题,请参考以下文章