0

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

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 数据传输服务“查看和管理您在 Google BigQuery 中的数据并查看您的 Google 帐户的电子邮件地址”,然后复制/将我在浏览器中获得的字符串粘贴回终端。

有没有办法持久化版本配置,这样我就不必每次都执行这一步了?

先感谢您

4

1 回答 1

0

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

导出 CLOUDSDK_PYTHON_SITEPACKAGES=1

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

gcloud 授权列表

我希望以上信息会有所帮助。如果没有,请确保您尝试了Stackoverflow 案例中遵循的步骤。

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

于 2022-02-11T13:51:06.337 回答