问题
I'm trying to execute an SQL query on some bigquery table. I keep getting a DefaultCredentialsError
when trying to instantiate a bigquery client object. For example by doing this:
from google.cloud import bigquery
client = bigquery.Client.from_service_account_json('service_account_key.json')
Or by doing this:
from oauth2client.service_account import ServiceAccountCredentials
key = open('service_account_key.json', 'rb').read()
credentials = ServiceAccountCredentials(
'my_email',
key,
scope='https://www.googleapis.com/auth/bigquery')
client = bigquery.Client(credentials=credentials)
Could there be a problem with my .json credentals file? I created a service account key:
Any other suggestions?
回答1:
You are most likely hitting a bug with using the from_service_account_json
method.
Instead, try using the recommended way of authenticating by exporting the GOOGLE_APPLICATION_CREDENTIALS
environment variable as decribed here.
来源:https://stackoverflow.com/questions/41385341/avoiding-defaultcredentialserror-when-using-google-bigquery-api