【问题标题】:Cannot query tables from sheets in BigQuery无法从 BigQuery 中的工作表查询表
【发布时间】:2021-07-13 07:48:27
【问题描述】:

我正在尝试在 python 中使用 BigQuery 来查询通过工作表生成的表:

from google.cloud import bigquery

# Prepare connexion and query
bigquery_client = bigquery.Client(project="my_project")

query = """
    select * from `table-from-sheets`
"""
df = bigquery_client.query(query).to_dataframe()

我通常可以对 BigQuery 表进行查询,但现在我收到以下错误:

Forbidden: 403 Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials.

我需要做什么才能从 python 访问驱动器?

还有其他方法吗?

【问题讨论】:

    标签: python google-bigquery


    【解决方案1】:

    您缺少凭据的范围。我正在粘贴来自official documentation 的代码 sn-p。

    此外,不要忘记在 Google 工作表中至少授予 VIEWER 对服务帐户的访问权限。

    from google.cloud import bigquery
    import google.auth
    
    # Create credentials with Drive & BigQuery API scopes.
    # Both APIs must be enabled for your project before running this code.
    credentials, project = google.auth.default(
        scopes=[
            "https://www.googleapis.com/auth/drive",
            "https://www.googleapis.com/auth/bigquery",
        ]
    )
    
    # Construct a BigQuery client object.
    client = bigquery.Client(credentials=credentials, project=project)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 2019-12-19
      • 2020-06-04
      • 2016-12-25
      • 1970-01-01
      相关资源
      最近更新 更多