Appengine + Bigquery = 403拒绝访问

时间:2017-10-19 00:46:28

标签: python google-app-engine google-bigquery webapp2

我正在尝试将我的GCP项目appengine应用程序连接到Bigquery,我正面临访问问题(禁止403)。

我按照此处提供的参考资料: https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-usage-python

我收到错误:

Project sample-1423: The user sample-1423@appspot.gserviceaccount.com does not have bigquery.jobs.create permission in project sample-1423
  1. 默认的appengine服务帐户(sample-1423@appspot.gserviceaccount.com)具有编辑角色设置。
  2. 此问题出现在appengine和本地且出现相同错误,我已将GOOGLE_APPLICATION_CREDETIALS env变量设置为链接到服务帐户的密钥。
  3. 从下面的链接看,如果我在appengine上运行,我似乎无需做任何事情。 https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
  4. 代码:

    user = users.get_current_user()
      client = bigquery.Client()
      auth_query = AUTH_QUERY
      params = (bigquery.ScalarQueryParameter('email', 'STRING', user.email()),)
      auth_job = client.run_async_query(
          str(uuid.uuid4()), auth_query, query_parameters=params)
      auth_job.use_legacy_sql = False
      auth_job.begin()
      auth_job.result()
      table = auth_job.destination
      table.reload()
    

    错误:

     Traceback (most recent call last):
      File "/Users/user/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
        rv = self.handle_exception(request, response, e)
      File "/Users/user/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
        rv = self.router.dispatch(request, response)
      File "/Users/user/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
        return route.handler_adapter(request, response)
      File "/Users/user/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
        return handler.dispatch()
      File "/Users/user/projects/sample/main.py", line 43, in dispatch
        if not user_in_system():
      File "/Users/user/projects/sample/main.py", line 30, in user_in_system
        auth_job.begin()
      File "/Users/user/projects/sample/lib/google/cloud/bigquery/job.py", line 373, in begin
        method='POST', path=path, data=self._build_resource())
      File "/Users/user/projects/sample/lib/google/cloud/_http.py", line 293, in api_request
        raise exceptions.from_http_response(response)
    Forbidden: 403 POST https://www.googleapis.com/bigquery/v2/projects/sample-1432/jobs: Access Denied: Project sample-1432: The user sample-1432@appspot.gserviceaccount.com does not have bigquery.jobs.create permission in project sample-1432.
    

0 个答案:

没有答案