Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google cloud storage python client AttributeError: 'ClientOptions' object has no attribute 'scopes' occurs after deployment

I am using cloud storage with App Engine Flex. Out of the blue i start getting this error message after deploy succeeds

The error is happening from these lines in my flask app.

from google.cloud import storage, datastore
client = storage.Client()
File "/home/vmagent/app/main.py", line 104, in _load_db
    client = storage.Client()
  File "/env/lib/python3.6/site-packages/google/cloud/storage/client.py", line 110, in __init__
    project=project, credentials=credentials, _http=_http
  File "/env/lib/python3.6/site-packages/google/cloud/client.py", line 250, in __init__
    Client.__init__(self, credentials=credentials, client_options=client_options, _http=_http)
  File "/env/lib/python3.6/site-packages/google/cloud/client.py", line 143, in __init__
    scopes = client_options.scopes or self.SCOPE
AttributeError: 'ClientOptions' object has no attribute 'scopes'

This is something to do with breaking upgrades made to grpcio and google-api-core and google-cloud-storage packages based on numerous SO threads. However, I cant figure out where this is happening.

My requirements.txt is as follows:

setuptools>=40.3
grpcio<=1.27.2
google-api-core<1.17.0
Flask

gevent>=0.13

gunicorn>=19.7.1
numpy>=1.18.0
numpy-financial
scipy>=1.4
pvlib>=0.7
google-cloud-storage==1.28.0
google-cloud-datastore==1.12.0
google-cloud-pubsub
pandas==1.0.5

my app.yaml is as follows:

service: app-preprod
runtime: custom
env: flex
entrypoint: gunicorn -t 600 -c gunicorn.conf.py -b :$PORT main:app


runtime_config:
   python_version: 3.6
manual_scaling:
    instances: 1
resources:
    cpu: 1
    memory_gb: 4
beta_settings:
    cloud_sql_instances: xxxx:europe-west6:component-cost
   
endpoints_api_service:
  name: apipreprod-dot-xxxx.appspot.com
  rollout_strategy: managed

Looking at the release histories, some new versions of google-cloud-storage etc were released a few days ago, but i have tried to maintain the same older version number.

The ridiculous thing is that with these exact same requirements.txt, i have an identical prod app engine that is working fine --- but that i had not redeployed for a week. Obviously, no problems at all with exactly the same versions of storage and datastore to run the client from my local machine.

--EDIT-- Apparently according to

https://github.com/googleapis/google-cloud-python/issues/10471

i should just add

google-cloud-core==1.3.0 to requirements.txt This seems a workaround --- any better permanent way of ensuring this break doesnt catch me unawares?

like image 674
Vipluv Avatar asked Aug 06 '20 07:08

Vipluv


1 Answers

This is due to https://github.com/googleapis/google-cloud-python/issues/10471.

I'd recommend upgrading google-cloud-core and google-api-core to the latest versions with the bugfix.

like image 184
Dustin Ingram Avatar answered Sep 20 '22 10:09

Dustin Ingram