解决GCP权限问题

时间:2018-07-30 20:12:08

标签: python google-cloud-platform google-bigquery

因此,我正在研究以下教程: https://github.com/GoogleCloudPlatform/professional-services/tree/master/machine-learning/solutions/energy_price_forecasting

我已经在终端中查看了以下代码,并初始化了Google Cloud。此外,我正在执行数据准备代码以准备训练/验证/测试数据。但是,当我运行以下代码时,它会给我一条错误消息。

abrahams-mbp:energyforecast abrahammathew$ python -m data_preparation.data_prep
Traceback (most recent call last):
  File "/Users/abrahammathew/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Users/abrahammathew/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/abrahammathew/Desktop/energyforecast/data_preparation/data_prep.py", line 323, in <module>
    main()
  File "/Users/abrahammathew/Desktop/energyforecast/data_preparation/data_prep.py", line 318, in main
    generate_data(client, parameters)
  File "/Users/abrahammathew/Desktop/energyforecast/data_preparation/data_prep.py", line 245, in generate_data
    client)
  File "/Users/abrahammathew/Desktop/energyforecast/data_preparation/data_prep.py", line 228, in create_table
    job_config)
  File "/Users/abrahammathew/Desktop/energyforecast/data_preparation/data_prep.py", line 138, in run_query
    job_config=job_config)
  File "/Users/abrahammathew/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/client.py", line 986, in query
    job._begin(retry=retry)
  File "/Users/abrahammathew/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/job.py", line 397, in _begin
    method='POST', path=path, data=self._build_resource())
  File "/Users/abrahammathew/anaconda3/lib/python3.6/site-packages/google/cloud/bigquery/client.py", line 271, in _call_api
    return call()
  File "/Users/abrahammathew/anaconda3/lib/python3.6/site-packages/google/api_core/retry.py", line 260, in retry_wrapped_func
    on_error=on_error,
  File "/Users/abrahammathew/anaconda3/lib/python3.6/site-packages/google/api_core/retry.py", line 177, in retry_target
    return target()
  File "/Users/abrahammathew/anaconda3/lib/python3.6/site-packages/google/cloud/_http.py", line 293, in api_request
    raise exceptions.from_http_response(response)
google.api_core.exceptions.Forbidden: 403 POST https://www.googleapis.com/bigquery/v2/projects/energy-forecasting-211800/jobs: Access Denied: Dataset energy-forecasting-211800:Energy: The user energy-forecasting@energy-forecasting-211800.iam.gserviceaccount.com does not have bigquery.tables.create permission for dataset energy-forecasting-211800:Energy.

这似乎与GCP中的服务帐户有关,因此我继续创建 在GCP上创建一个新的服务帐户并运行以下代码。

export GOOGLE_APPLICATION_CREDENTIALS="/Users/abrahammathew/Desktop/energyforecast/energy-forecasting-e6374529afe0.json"

然后我通过得到相同的错误来重新运行数据性能代码。

python -m data_preparation.data_prep

如何获取运行代码以准备上面github链接中的数据? 我通过Mac终端上的Google Cloud SDK运行它。

1 个答案:

答案 0 :(得分:1)

您的服务帐户“ energy-forecasting@energy-forecasting-211800.iam.gserviceaccount.com”不允许在BigQuery中创建表。

您需要创建一个IAM和管理员->创建服务帐户。然后创建一个具有“ BigQuery用户”角色的服务帐户,该角色应该足以授予minimum permissions服务帐户。