Python 为什么导出GOOGLE_应用程序_凭据与'bq'不兼容?

Python 为什么导出GOOGLE_应用程序_凭据与'bq'不兼容?,python,google-cloud-storage,google-cloud-platform,gcloud,google-cloud-sdk,Python,Google Cloud Storage,Google Cloud Platform,Gcloud,Google Cloud Sdk,用户可以使用指向服务帐户JSON密钥的路径导出env varGOOGLE_应用程序_凭据,gcloud将使用它。我不能让它工作 我的命令是: GOOGLE_APPLICATION_CREDENTIALS=/home/ubuntu/.config/google-creds.json bq ls 这只会带来一个错误: 您当前没有选择活动帐户。请运行: $gcloud auth登录 获取新凭据,或者如果您已使用 不同帐户: $gcloud配置集帐户 选择要使用的已通过身份验证的帐户 gcloud-v

用户可以使用指向服务帐户JSON密钥的路径导出env var
GOOGLE_应用程序_凭据
,gcloud将使用它。我不能让它工作

我的命令是:

GOOGLE_APPLICATION_CREDENTIALS=/home/ubuntu/.config/google-creds.json bq ls
这只会带来一个错误:

您当前没有选择活动帐户。请运行:

$gcloud auth登录

获取新凭据,或者如果您已使用 不同帐户:

$gcloud配置集帐户

选择要使用的已通过身份验证的帐户

gcloud-v
提供:

Google Cloud SDK 92.0.0

bq 2.0.18
bq-nix 2.0.18
core 2016.01.12
core-nix 2015.11.24
gcloud
gsutil 4.16
gsutil-nix 4.15
我做错了什么,我该如何解决?我需要
gsutil
bq
来使用这个文件。我正在处理多个项目,因此无法激活任何特定项目。

您尝试过吗?:

(命令行工具似乎不像gcloud在代码中用作库时那样贯穿整个凭证发现链。)


如果需要使用多个配置(例如身份验证、项目ID),则可以进行设置。例如,如果您有两个要使用的服务帐户凭据—称它们为
sa1.json
sa2.json
—您可以执行以下操作:

$ gcloud config configurations create proj1
$ gcloud config configurations activate proj1
$ gcloud auth activate-service-account --key-file sa1.json

$ gcloud config configurations create proj2
$ gcloud config configurations activate proj2
$ gcloud auth activate-service-account --key-file sa2.json
现在,您可以使用
gcloud config configurations activate
命令来设置要使用的配置,或者设置
CLOUDSDK\u ACTIVE\u config\u NAME
环境变量来指定要在哪个配置下运行命令。ie使用
sa1.json
cred运行
bq ls

$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj1 bq ls
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj2 bq ls
对于
sa2.json
cred:

$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj1 bq ls
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj2 bq ls
你试过了吗

(命令行工具似乎不像gcloud在代码中用作库时那样贯穿整个凭证发现链。)


如果需要使用多个配置(例如身份验证、项目ID),则可以进行设置。例如,如果您有两个要使用的服务帐户凭据—称它们为
sa1.json
sa2.json
—您可以执行以下操作:

$ gcloud config configurations create proj1
$ gcloud config configurations activate proj1
$ gcloud auth activate-service-account --key-file sa1.json

$ gcloud config configurations create proj2
$ gcloud config configurations activate proj2
$ gcloud auth activate-service-account --key-file sa2.json
现在,您可以使用
gcloud config configurations activate
命令来设置要使用的配置,或者设置
CLOUDSDK\u ACTIVE\u config\u NAME
环境变量来指定要在哪个配置下运行命令。ie使用
sa1.json
cred运行
bq ls

$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj1 bq ls
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj2 bq ls
对于
sa2.json
cred:

$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj1 bq ls
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj2 bq ls

是的,但请看我的另一个背景问题:我认为这将是一个更简单的解决方案。啊-您正在寻找的是
gcloud config configurations
。我将在实际答案中详细说明。是的,但请参阅我的另一个问题作为背景:我认为这将是一个更简单的解决方案。啊-您要寻找的是
gcloud config configurations
。我将在实际答案中详细说明。