Google 云存储 python 客户端 AttributeError: 'ClientOptions' object has no attribute 'scopes' 部署后发生

Vip*_*luv 12 python python-3.x google-cloud-storage google-cloud-platform grpc-python

我正在将云存储与 App Engine Flex 结合使用。部署成功后,我突然开始收到此错误消息

错误发生在我的 Flask 应用程序中的这些行中。

from google.cloud import storage, datastore
client = storage.Client()
Run Code Online (Sandbox Code Playgroud)
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'
Run Code Online (Sandbox Code Playgroud)

这与基于大量 SO 线程对 grpcio 和 google-api-core 以及 google-cloud-storage 软件包进行的重大升级有关。但是,我无法弄清楚这是在哪里发生的。

我的requirements.txt如下:

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
Run Code Online (Sandbox Code Playgroud)

我的 app.yaml 如下:

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
Run Code Online (Sandbox Code Playgroud)

查看发布历史,几天前发布了一些新版本的 google-cloud-storage 等,但我试图保持相同的旧版本号。

荒谬的是,使用这些完全相同的 requirements.txt,我有一个完全相同的 prod 应用程序引擎,它工作正常——但我已经一周没有重新部署了。显然,使用完全相同版本的存储和数据存储从我的本地机器运行客户端完全没有问题。

--编辑--显然是根据

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

我应该添加

google-cloud-core==1.3.0 to requirements.txt 这似乎是一种解决方法 --- 有没有更好的永久方式来确保这个休息不会让我措手不及?

Dus*_*ram 8

这是由于https://github.com/googleapis/google-cloud-python/issues/10471

我建议你升级google-cloud-core,并google-api-core到最新版本与修正错误。

  • 我非常害怕升级到最新版本,因为过去尤其是在 grpcio 和 google-api-core 中发生了重大变化,这迫使我们回滚,这就是为什么 google-cloud-core 被固定到 1.3.0。例如,这个让我陷入困境 - https://github.com/googleapis/python-api-core/issues/47 (4认同)