我正在尝试通过 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 客户端?
我的本地环境的应用程序默认凭据是我的授权用户,即项目的所有者。