Avoiding DefaultCredentialsError when using google bigquery API

隐身守侯 提交于 2019-12-24 07:15:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!