BigQuery:获取云端硬盘凭据时权限被拒绝 - 无法解决该错误

2023-12-25

我希望针对我遇到的这个错误代码获得一些帮助。

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


因此,一位同事建议我探索默认的 pandas_gbq 凭据,因为这可能使用默认凭据来访问数据。

事实证明,它奏效了。

您可以按照以下步骤手动设置 pandas-gbq 凭据:https://pandas-gbq.readthedocs.io/en/latest/howto/authentication.html https://pandas-gbq.readthedocs.io/en/latest/howto/authentication.html https://pandas-gbq.readthedocs.io/en/latest/api.html#pandas_gbq.Context.credentials https://pandas-gbq.readthedocs.io/en/latest/api.html#pandas_gbq.Context.credentials

我只是将以下内容添加到我的代码中

pdgbq.context.credentials = credentials

最终输出:

import dotenv
import pandas as pd
from google.cloud import bigquery
import google.auth
import pandas_gbq as pdgbq


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",
        ]
    )
    pdgbq.context.credentials = credentials
    bigquery.Client(project, credentials)
    output = pd.read_gbq(sql, project_id=project, dialect='standard')
    return output

script_variable4 = "SELECT * FROM `X` LIMIT 10"

bq_output = run_BigQuery_table(script_variable3)
print(bq_output)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

BigQuery:获取云端硬盘凭据时权限被拒绝 - 无法解决该错误 的相关文章

随机推荐

  • 这是解析 XML 的低效方法吗?

    我可能担心错误的优化 但我有一个挥之不去的想法 它一遍又一遍地解析 xml 树 也许我在某个地方读过它 不记得了 无论如何 这就是我正在做的事情 using System using System Collections Generic u
  • 在奏鸣曲管理中隐藏下载按钮

    我想从某些自定义实体中隐藏 Sonata Admin 上的 下载 按钮 如何隐藏 删除它 如果我覆盖base list html twig并从 table footer 中删除下载按钮 它会消失所有实体列表 有什么办法可以将其隐藏在 Adm
  • GitHub 操作的输出为空

    我正在创建我的第一个 GitHub 操作 但我不明白为什么输出为空 动作 yml name Run Endtest functional tests description Register a deployment event with
  • 如何在 cirros OS 中安装软件包

    如何在 cirros 镜像中安装软件包 我在 devstack 安装附带的 cirros 映像中找不到任何可用的安装程序 正如 Harikrishnan 评论的那样 cirros 不包含包管理器 Cirros 主要用于验证云是否正常工作 虚
  • C++ 算法在数组中查找“最大差异”

    我正在询问您对这个问题的想法 I have one array A with N elements of type double or alternatively integer I would like to find an algori
  • 下载绘图而无需在 R闪亮中重新绘图

    我正在尝试下载已经绘制的ggplot图像而无需再次重新绘制 我找到的所有解决方案 例如保存在闪亮的应用程序中制作的绘图 https stackoverflow com questions 14810409 save plots made i
  • Emacs缩进困难

    我真的很想切换到 emacs 但是学习设置环境真的很痛苦 大家都说值得 所以我就继续 我希望我的 C 代码能够以这种方式实现 if asdf asdr 1 根据当前的标准 我知道 别让我开始 可能是 if asdf asdr 1 我似乎无法
  • 自托管 WCF 服务:如何从托管应用程序访问实现服务契约的对象?

    我在 WPF 客户端中自托管 WCF 服务 我想在用户界面中显示服务接收的数据 每次收到一些数据时 用户界面都应该更新 App xaml cs 中的代码如下所示 private ServiceHost host new ServiceHos
  • 如何编译具有可变输入类型的 numba jit'ed 函数?

    假设我有一个函数可以接受int or a None类型作为输入参数 import numba as nb import numpy as np jitkw nopython True nogil True error model numpy
  • tk.mainloop() 与 root.mainloop()?

    我试图找到一些有关使用的问答或文章tk mainloop vs root mainloop 没有成功 我的问题是 这两种用途有什么区别吗 在我看来正确的方法是使用tk instance variable name mainloop 与只是做
  • 带有属性字符串的电子邮件撰写器

    如何通过电子邮件发送属性字符串 mailComposerVC setMessageBody textView attributedString isHTML false 您已将属性字符串转换为 HTML 字符串 使用以下代码生成 html
  • Linux 上 Mono 中的 Windows kernel32 函数

    我不久前从某个地方下载了这个非常简单的 ini 类 但现在我使用 mono 我遇到了一个问题 它从 kernel32 导入东西 DllImport kernel32 private static extern long WritePriva
  • Python 中的“and not”有什么用?

    为什么如果没有 并且未找到 代码就无法工作 这个声明有什么用呢 def BinarySearch alist item first 0 last len alist 1 found False while first lt last and
  • 如何在 Julia 中同时写入数组的多个索引?

    我希望在 Julia 中看到类似的东西 using Distributed addprocs 4 everywhere arr Array Int undef 10 for i 1 10 spawn arr i i end 这样做的正确方法
  • 有没有办法在 Scala 中模拟 Singleton 对象

    我有以下代码 trait Calculator def add x Int y Int Int def multiply x Int y Int Int trait MyCalculator extends Calculator overr
  • Microsoft Dynamics CRM 2013 插件 - 没有活动事务错误

    我一直在努力解决 MS Dynamics CRM Online 插件中的错误 见下文 它似乎是随机发生的 但当活动较高时更有可能发生 我已经验证 并且没有异常表明的 try catch Continue 问题 并且没有成员引用 Organi
  • 授权和验证对静态内容的访问 (pdf)

    我有一个asp net 网络应用程序并可通过表单身份验证进行访问 文件夹结构内部如下所示 myapp document pdf hello1 pdf document pdf hello2 pdf document pdf hello3 p
  • BBC 对浏览器的支持有限(以及为什么 BBC 不能使用 jQuery)

    BBC 刚刚发布了他们的 JavaScript 库 Glow http www bbc co uk glow docs articles what is glow shtml 他们推出了自己的库 因为主要的库不能充分支持旧版浏览器 我想知道
  • 我可以扩展 LINQ-to-SQL 支持的运算符吗?

    如果我非常想要 是否可以向 LINQ to SQL 添加额外的 LINQ 构造 如果创建自己的 LINQ 提供程序 我就可以这样做 例如 许多内置 LINQ 运算符 XYZ Any 直接转换为 SQL 例如IF EXISTS XYZ 如果我
  • BigQuery:获取云端硬盘凭据时权限被拒绝 - 无法解决该错误

    我希望针对我遇到的这个错误代码获得一些帮助 Context 我工作的公司使用 GSUITE 产品 我的团队有自己的云项目设置 Google 云端硬盘不是 个人 云端硬盘 我们利用 Airflow 刷新 BigQuery 表 每天 每周 每月