我无法非交互地激活我的Google服务帐户;即使在阅读了几个这样的线程之后。
gcloud iam service-accounts create my-awesome-acct ...
gcloud iam roles create AwesomeRole \ --permissions storage.objects.create,storage.objects.delete ....
gcloud iam service-accounts keys create ~/awesome-key.json ...
gcloud auth activate-service-account my-awesome-acct ~/awesome-key.json
我的问题
即使在执行上述步骤之后,当我运行gsutil ...命令时,仍然会收到错误消息:
$ gsutil cp my_file.tgz gs://my_bucket
Copying file://my_file.tgz [Content-Type=application/x-tar]...
Your credentials are invalid. Please run
$ gcloud auth login唯一能让它工作的方法是,实际上是,运行gcloud auth login,并允许在web浏览器中进行身份验证。
我做错了什么吗?或者这是为每个服务帐户准备的?
发布于 2018-07-16 15:28:19
我要在这里回答我自己的问题。
我的解决方案
我决定使用Google客户端库,而不是使用gsutil。
我所做的
gsutil cp my_file.tgz gs://my_bucket我现在在做什么
from gcloud import storage
# key file is located in my current directory
os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', 'gcloud-auth.json')
client = storage.Client()
bucket = client.get_bucket("my_bucket")
blob = bucket.blob("my_file.tgz")
blob.upload_from_filename("my_file.tgz")回顾20/20
在使上面的解决方案正常工作之后,如果我也设置了环境变量GOOGLE_APPLICATION_CREDENTIALS,我的gsutil也应该可以工作。(未经测试)
https://stackoverflow.com/questions/51334168
复制相似问题