colly434
colly434

Reputation: 11

google-bigquery server to server authentification fails - python

I'm building the app that gets the data from BigQuery to another server. And trying to use the server to server auth with genereted key for service account. But receive the followig error.

import json

from httplib2 import Http
import argparse
from oauth2client.client import GoogleCredentials
from googleapiclient.errors import HttpError
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

scopes = ['https://www.googleapis.com/auth/sqlservice.admin']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'credentials_bq.json', scopes)
bigquery_service = build('bigquery', 'v1', credentials=credentials)


query_request = bigquery_service.jobs()
query_data = {
    'query': (
        'select count( distinct meta_id) from  [..table.name] '
        'where MSEC_TO_TIMESTAMP(meta_serverTs) >= \'2016-10-28 10:00:00 UTC\'')
}



query_response = query_request.query(
    projectId='my_project_id',
    body=query_data).execute()

Error returned :

Traceback (most recent call last):
  File "test_connection_bq.py", line 35, in <module>
    body=query_data).execute()
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/googleapiclient/http.py", line 838, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/bigquery/v2/projects/my_project_id/queries?alt=json returned "Insufficient Permission">

Upvotes: 0

Views: 111

Answers (1)

xuejian
xuejian

Reputation: 195

Not sure if you read the access control document? If not please go through that and grant the service account proper permission. Since you are running query, bigquery.user should be granted.

Upvotes: 1

Related Questions