首页 > 解决方案 > 使用 Deployment Manager 在 BigQuery 中创建“外部表”时出现“403 Permission denied while getting Drive credentials”

问题描述

重现步骤:

部分python模板:
def GenerateConfig(context):
    name: str = context.env['name']
    dataset: str = context.properties['dataset']
    tables: [] = context.properties['tables']
    location: str = context.properties.get('location', 'EU')
    resources = [{
        'name': name,
        'type': 'gcp-types/bigquery-v2:datasets',
        'properties': {
            'datasetReference': {
                'datasetId': dataset,
            },
            'location': location
        },
    }]

    for t in tables:
        resources.append({
            'name': '{}-tbl'.format(t["name"]),
            'type': 'gcp-types/bigquery-v2:tables',
            'properties': {
                'datasetId': dataset,
                'tableReference': {
                    'tableId': t["name"]
                },
                'externalDataConfiguration': {
                    'sourceUris': ['https://docs.google.com/spreadsheets/d/123123123123123-123123123123/edit?usp=sharing'],
                    'sourceFormat': 'GOOGLE_SHEETS',
                    'autodetect': True,
                    'googleSheetsOptions':
                        {
                            "skipLeadingRows": '1',
                        }
                }
            },
        })
    return {'resources': resources}

我发现了一些这样的线索但它们都引用了“范围”来添加https://www.googleapis.com/auth/drive。我不确定如何将范围添加到部署管理器请求,或者范围如何工作。

任何帮助,将不胜感激。

标签: google-cloud-platformgoogle-bigquerygoogle-drive-apigoogle-deployment-manager

解决方案


是的,使用范围可以解决问题。但是,即使在添加范围之后,我也面临同样的错误。与 GCP 服务帐户共享 google 表格文档帮助我摆脱了这个错误。

总结 - 使用范围并与您将用于查询表的 GCP 服务帐户共享文档。

另外,本文档对查询外部表很有帮助


推荐阅读