![](/img/trans.png)
[英]Python, AttributeError: module 'google.cloud.bigquery' has no attribute 'Client' after cx_Freeze build
[英]Google cloud storage python client AttributeError: 'ClientOptions' object has no attribute 'scopes' occurs after deployment
我正在使用带有 App Engine Flex 的云存储。 部署成功后,我突然开始收到此错误消息
我的 flask 应用程序中的这些行发生了错误。
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'
这与基于大量 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
我的 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
查看发布历史,几天前发布了一些新版本的 google-cloud-storage 等,但我试图保持相同的旧版本号。
荒谬的是,使用这些完全相同的 requirements.txt,我有一个相同的 prod 应用程序引擎,它工作正常 --- 但我一周没有重新部署。 显然,使用完全相同版本的存储和数据存储从我的本地计算机运行客户端完全没有问题。
--编辑--显然根据
https://github.com/googleapis/google-cloud-python/issues/10471
我应该添加
google-cloud-core==1.3.0
到 requirements.txt 这似乎是一种解决方法 --- 有没有更好的永久方法来确保这种中断不会让我措手不及?
这是由于https://github.com/googleapis/google-cloud-python/issues/10471造成的。
我建议将google-cloud-core
和google-api-core
升级到带有错误修复的最新版本。
此错误消息表明您需要为您的 ClientOptions object 设置属性“范围”。
我想建议你看看这个ClientOptions的文档。 “范围”属性应该是“OAuth 访问令牌覆盖范围”。 您可以将其设置为无。 请检查您的代码的那部分。
另一方面,请确保您已正确准备环境以使用 Datastore客户端库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.