Why am I getting the error 'Forbidden: 403 Access Denied: BigQuery BigQuery: Permission denied while globbing file pattern' when using pandas read_gbq

Viewed 2911

I am trying to use python to read a view in BigQuery. I have previously used version 0.14.0 of pandas-gbq and authenticated using a service account by doing the following:

import pandas as pd
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file(PATH_TO_JSON)

pd.read_gbq("""
                SELECT
                    *
                FROM BQ_VIEW,

                project_id="PROJECT_ID",
                dialect="standard",
                private_key=credentials
                )

Where PATH_TO_JSON, BQ_VIEW and PROJECT_ID have been filled in with the relevant info. This worked with no issues. However I am now working on another project that is using version 0.15.0 of pandas-gbq where the private_key argument is deprecated and has been replaced with credentials. Following the guide on how to authenticate using the new credentials argument with a service account I have tried the following:

import pandas as pd
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file(PATH_TO_JSON)

pd.read_gbq("""
                SELECT
                    *
                FROM BQ_VIEW,

                project_id="PROJECT_ID",
                dialect="standard",
                credentials=credentials
                )

however when I run this I now get the error:

Forbidden: 403 Access Denied: BigQuery BigQuery: Permission denied while globbing file pattern

Is anyone able to advise me on where I am going wrong?

Thanks!

1 Answers

The issue is not related to the arguments. The error you are facing is due to improper IAM permissions to the service account . It seems you are trying to query a view which is referring to a table outside of BigQuery. This document says you need to grant your service account storage.objectViewer role in case your external table refers to a Cloud Storage file.

Related