【发布时间】:2020-09-10 11:03:30
【问题描述】:
当我尝试访问外部表的数据时,出现如下错误。我无法解决这个问题。以下是有关情况的详细信息;
google.api_core.exceptions.NotFound:404 未找到:文件 /gdrive/id/id123456id
PS:id123456id 是一个虚拟 id。
ID 为 id123456 的文件存在于我的 Google 云端硬盘中。查找此 ID 的 Bigquery 表。
bq_test.json -> 服务帐户凭据的 JSON 文件。此服务帐号具有这些角色;
- BigQuery 数据编辑器
- BigQuery 数据所有者
- BigQuery 数据查看器
- BigQuery 用户
- 所有者
这是我的代码块:
from google.cloud import bigquery
from google.oauth2.service_account import Credentials
scopes = (
'https://www.googleapis.com/auth/bigquery',
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/drive'
)
credentials = Credentials.from_service_account_file('bq_test.json')
credentials = credentials.with_scopes(scopes)
client = bigquery.Client(credentials=credentials)
QUERY = (
"""SELECT * FROM
`project_name.dataset_name.ext_table`
LIMIT 5"""
)
query_job = client.query(QUERY)
rows = query_job.result()
for row in rows:
print(row.name)
【问题讨论】:
-
听起来服务帐户没有访问权限。
-
@DaImTo 如何授予访问权限?我在角色列表中找不到 drive.readonly 或其他内容。
标签: python google-cloud-platform google-bigquery google-drive-api