gcloud CLI:运行bq mk命令需要使用浏览器执行一个步骤



我从本地终端运行以下命令:

bq mk --transfer_config --target_dataset=mydataset --display_name='mytransfer' --params='{ 
"data_path": "s3://mys3path/*",
"destination_table_name_template": "mytable",
"file_format": "JSON",
"max_bad_records":"0",
"ignore_unknown_values":"true",
"access_key_id": "myaccessid",
"secret_access_key": "myaccesskey"
}' --data_source=amazon_s3

现在,每次我运行这个,我都会得到以下信息:

/opt/google-cloud-sdk/platform/bq/bq.py:41: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
import imp
Table '<mytablehere>' successfully created.
/opt/google-cloud-sdk/platform/bq/bq.py:41: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
import imp
https://www.gstatic.com/bigquerydatatransfer/oauthz/auth?client_id=***********.apps.googleusercontent.com&scope=https://www.googleapis.com/auth/bigquery&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=version_info
Please copy and paste the above URL into your web browser and follow the instructions to retrieve a version_info.
Enter your version_info here: 

所以,每次我运行这个,我都需要打开这个链接,登录我的帐户,授权谷歌数据传输服务"在Google BigQuery中查看和管理您的数据,并查看您的Google帐户的电子邮件地址";然后将我在浏览器中得到的字符串复制/粘贴回终端。

有没有什么方法可以保持版本配置,这样我就不必每次都执行这个步骤了?

提前感谢

我绕过了以下提示:

https://www.gstatic.com/bigquerydatatransfer/oauthz/auth?client_id=123456789012-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&scope=https://www.googleapis.com/auth/bigquery%20https://www.googleapis.com/auth/drive&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=version_info
Please copy and paste the above URL into your web browser and follow the instructions to retrieve a version_info.
Enter your version_info here:

使用以下步骤:

  1. 创建一个服务帐户
  2. 将角色"分配给服务帐户"roles/bigquery.admin">
  3. 为服务帐户创建一个JSON密钥
  4. 下载密钥文件
  5. 使用";gcloud-auth-activate服务帐户";以服务帐户身份登录
  6. 运行";bq查询";或";bq mk";命令的参数为"0"--service_account_credential_file=服务帐户密钥文件.json">
  7. 用户";gcloud auth revoke";从服务帐户注销

这对我很有效,避免了提示,但我完全是通过反复尝试才做到的。我找不到任何支持这种方法的GCP文档,恰恰相反,他们的大多数文档似乎都漫不经心地提到了提示,就好像这不是我们想要避免的一样。

为了使您的服务帐户凭据在BigQuery命令行工具中保持不变,以便您可以在注销后再次登录后使用它,您需要通过运行以下命令设置CLOUDSDK_PYTHON_SITEPACKAGES环境变量:

导出CLOUDSDK_PYTHON_SITEPACKAGES=1

然后,您可以运行以下命令查看该工具具有凭据的帐户,其中应包括您的服务帐户:

gcloud身份验证列表

我希望以上信息会有所帮助。如果没有,请确保尝试在Stackoverflow情况下执行的步骤。

请务必试用Michael Sheldon提供的.bigqueryrc解决方案。

最新更新