Reputation: 1835
I am trying to run a simple query on Google BigQuery via a python script, but am getting the below error that my service account is missing bigquery.jobs.create
permission.
My service Account has the following roles applied:
I've also tried creating a custom role with bigquery.jobs.create
and applying that to the service account, but still consistently get this error. What am I doing wrong?
from google.cloud import bigquery
from google.oauth2 import service_account
project_id = "my-test-project"
credentials = service_account.Credentials.from_service_account_file("credentials.json")
client = bigquery.Client(
credentials=credentials,
project=project_id
)
print(client.project) # returns "my-test-project"
query = client.query("select 1 as test;")
Access Denied: Project my-test-project: The user my-service-account @ my-test-project. iam.gserviceaccount.com does not have bigquery.jobs.create permission in project my-test-project.
Upvotes: 1
Views: 631
Reputation: 1071
Authenticating the client using client = bigquery.Client.from_service_account_json("credentials.json")
is the preferred method to avoid "Access Denied" errors. For one reason or another (I'm not sure why since bigquery does use oauth 2.0 access tokens to authorize requests), setting credentials through google.oauth2.service_account
can lead to permission issues.
Upvotes: 1