0

I've been following the documentation to export logs from Stackdriver to Bigquery. I've tried the following:

from google.cloud.logging.client import Client as lClient
from google.cloud.bigquery.client import Client as bqClient
from google.cloud.bigquery.dataset import AccessGrant

import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'path_to_json.json'

lc = lClient()
bqc = bqClient()

ds = bqc.dataset('working_dataset')
acc = ds.access_grants
acc.append(AccessGrant('WRITER', 'groupByEmail', 'cloud-logs@system.gserviceaccount.com')) #this is the service account that is shown in our Exports tab in GCP.
ds.access_grants = acc
ds.update()

But we get the error message:

NotFound: 404 Not found: Email cloud-logs@system.gserviceaccount.com (PUT https://www.googleapis.com/bigquery/v2/projects/[project-id]/datasets/[working-dataset])

Why won't our dataset be updated? The key being used is the one which already created the dataset itself.

Willian Fuks
  • 11,259
  • 10
  • 50
  • 74
  • I guess, gserviceaccount is not a group. Do you mind to change 'groupByEmail' to 'userByEmail'? – xuejian Apr 29 '17 at 06:24
  • Hi @xuejian, just tried it and got a different error message: `BadRequest: 400 Cannot remove all owners from a dataset.`. When I first get `ds.access_grants` it does comes empty (not sure why). – Willian Fuks Apr 29 '17 at 17:01
  • Hi @xuejian, I just tried again but this time I inserted in the update another object of `AccessGrant` with the previous owner and it worked like a charm! if you want please write your comment as an answer and I'll accept it. It also might help those with the same issue – Willian Fuks May 02 '17 at 15:50

0 Answers0