我希望针对我遇到的这个错误代码获得一些帮助。
Context:
- 我工作的公司使用 GSUITE 产品。
- 我的团队有自己的云项目设置。
- Google 云端硬盘不是“个人”云端硬盘。
- 我们利用 Airflow 刷新 BigQuery 表
每天/每周/每月。
我已遵循这些解决方案
访问被拒绝:获取云端硬盘凭据时权限被拒绝 https://stackoverflow.com/questions/66598784/access-denied-permission-denied-while-getting-drive-credentials
使用 BigQuery API 和 Google Sheets 时出现“匹配文件模式时遇到错误”错误 https://stackoverflow.com/questions/40731823/encountered-an-error-while-globbing-file-pattern-error-when-using-bigquery-api
并且还参考了https://cloud.google.com/bigquery/external-data-drive#python_3 https://cloud.google.com/bigquery/external-data-drive#python_3
Problem
云作曲家:v 1.12.0
我最近设置了一个外部 Bigquery 表,用于读取 Google Sheet 中的选项卡。由于对 Drive 的访问限制,我的 Airflow DAG 一直无法完成。
我已将以下内容添加到 Airflow 连接范围中:
气流范围 https://i.stack.imgur.com/JddVe.png
还将服务帐户电子邮件地址添加到该表通过共享引用的 Google 表格中。我还将服务帐户 IAM 角色更新为 BigQuery admin。执行这些步骤后,我仍然收到错误 BigQuery:获取云端硬盘凭据时权限被拒绝。
Problem2
按照上述步骤,我发现在本地进行故障排除更容易,因此我在我的计算机上创建了一个 VENV,因为它是我最方便进行故障排除的地方。目标是简单地查询读取 Google 表的 Bigquery 表。但是,在执行上述相同步骤后,我仍然无法使其工作。
我的本地代码:
import dotenv
import pandas as pd
from google.cloud import bigquery
import google.auth
def run_BigQuery_table(sql):
dotenv.load_dotenv()
credentials, project = google.auth.default(
scopes=[
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/bigquery",
]
)
bigquery.Client(project, credentials)
output = pd.read_gbq(sql, project_id=project, dialect='standard')
return output
script_variable = "SELECT * FROM `X` LIMIT 10"
bq_output = run_BigQuery_table(script_variable)
print(bq_output)
My error:
引发 self._exception
google.api_core.exceptions.Forbidden:403 访问被拒绝:BigQuery BigQuery:获取云端硬盘凭据时权限被拒绝。
引发 GenericGBQException("原因: {0}".format(ex))
pandas_gbq.gbq.GenericGBQException:原因:403 访问被拒绝:BigQuery BigQuery:获取云端硬盘凭据时权限 > 被拒绝。
有人能帮忙吗?
Cheers