Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix AttributeError in App Engine Flex when using grpc and cloud-datastore?

When I deploy a python3 application using Google App Engine Flex I get the following error:

  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'

My requirements.txt file include the following:

google-cloud-datastore==1.12.0
grpcio==1.27.2

The reason I am using grpcio version 1.27.2 instead of the most recent 1.29.0 is because of the information shown here

Can somebody help?

like image 399
Manuel Godoy Avatar asked Jun 05 '20 20:06

Manuel Godoy


1 Answers

I just encountered the same issue, so this may help you out. I've noticed that google-api-core is also a dependency and it was recently updated (specifically around the grpc_helpers_async), so I just pinned it to version 1.17.0 and it resolved the issue. Just add this to your requirements:

google-api-core==1.17.0
like image 70
Meidan Alon Avatar answered Sep 21 '22 02:09

Meidan Alon