0

我正在尝试通过 google.cloud.bigquery Python 库查询存储在云端硬盘中的数据。

我已按照 Google 的Querying Drive Data指南进行操作。因此,我的代码如下所示:

import google.auth
from google.cloud import bigquery

credentials, project = google.auth.default(
    scopes=[
        "https://www.googleapis.com/auth/drive",
        "https://www.googleapis.com/auth/bigquery",
    ]
)
client = bigquery.Client(project, credentials)

query = client.query("""MY SQL HERE""")
query_results = query.result()

问题是:凭证对象和 bigquery 客户端忽略提供的范围,导致google.api_core.exceptions.Forbidden: 403 Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials.澄清,凭证和客户端都不包括提供的驱动器范围。

我该怎么做才能将驱动器范围正确传递给我的 bigquery 客户端?

我的本地环境的应用程序默认凭据是我的授权用户,即项目的所有者。

4

2 回答 2

0

将应用程序默认凭据设置为授权用户后,您将无法请求其他范围。

要请求其他范围,请在激活授权用户期间执行此操作。

更清楚地说,当你运行时gcloud auth application-default login,提供--scopes选项,然后是你想要的范围。对我来说,那是gcloud auth application-default login --scopes=openid,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/bigquery

于 2021-07-23T12:32:51.700 回答
0

您应该将电子表格共享到您尝试访问的服务帐户电子邮件。

在此处输入图像描述

于 2021-10-28T20:56:08.200 回答