首页 文章

由于权限问题,BigQuery加载作业失败

提问于
浏览
0

我正在使用以下code将数据从Google Storage中的CSV文件上传到BigQuery表:

from google.cloud import bigquery
client = bigquery.Client()
dataset_id = 'e'
dataset_ref = client.dataset(dataset_id)
job_config = bigquery.LoadJobConfig()
job_config.schema = [
    bigquery.SchemaField('itemcode', 'STRING'),
    bigquery.SchemaField('itemname', 'STRING'),
]
job_config.skip_leading_rows = 1
# The source format defaults to CSV, so the line below is optional.
#job_config.source_format = bigquery.SourceFormat.CSV
uri = 'gs://e/2018-07-15/inventory.csv.gz'
load_job = client.load_table_from_uri(
    uri,
    dataset_ref.table('inventory'),
    job_config=job_config)  # API request

assert load_job.job_type == 'load'

load_job.result()  # Waits for table load to complete.

assert load_job.state == 'DONE'
assert client.get_table(dataset_ref.table('inventory')).num_rows == 10

该项目被称为BI它的ID是:BI-bi我在这个数据集中有一个名为 e 的数据集我有一个名为 inventory 的表,有两列 itemcodeitemname .

由于某种原因,此代码失败并出现以下错误:

google.api_core.exceptions.Forbidden:403 POST https://www.googleapis.com/bigquery/v2/projects/USER/jobs:拒绝访问:数据集BI-bi:BI:用户USER@BI-bi.iam .gserviceaccount.com没有对数据集BI-bi:BI的bigquery.tables.create权限

当我要转到USER权限时,我发现它具有以下角色:

Big Query Job user
Storage Admin

其他选择是:

enter image description here

我迷失在这里 . 文档没有解释这里要做什么 .

错误日志:

回溯(最近一次调用最后一次):文件“inventory.py”,第160行,在job_config = job_config中)#API请求文件“/usr/local/lib/python2.7/dist-packages/google/cloud/bigquery/ client.py“,第689行,在load_table_from_uri job._begin(retry = retry)文件”/usr/local/lib/python2.7/dist-packages/google/cloud/bigquery/job.py“,第397行, _begin method ='POST',path = path,data = self._build_resource())文件“/usr/local/lib/python2.7/dist-packages/google/cloud/bigquery/client.py”,第271行,在_call_api中返回call()文件“/usr/local/lib/python2.7/dist-packages/google/api_core/retry.py”,第260行,在retry_wrapped_func中on_error = on_error,文件“/ usr / local / lib / python2.7 / dist-packages / google / api_core / retry.py“,第177行,在retry_target中返回target()文件”/usr/local/lib/python2.7/dist-packages/google/cloud/_http.py “,第293行,在api_request中引发exceptions.from_http_response(响应)google.api_core.exceptions.Forbidden:403 POST https://www.googleapis.com/bigquery/v2/projects/USER/jobs:Access拒绝:数据集BI-bi:BI:用户USER@BI-bi.iam.gserviceaccount.com没有对数据集BI-bi的bigquery.tables.create权限:BI

1 回答

  • 0

    我能够找到这个公开reference说:

    从Cloud Storage将数据加载到BigQuery时,必须在项目级别或数据集级别授予bigquery.dataOwner或bigquery.dataEditor角色 .

    要从 Cloud 存储桶加载数据,必须在项目级别或该单个存储桶上授予storage.objects.get权限 .

    这将帮助您在将数据从存储桶加载到BigQuery时解决权限问题

相关问题