使用Google BigQuery API时避免DefaultCredentialsError [英] Avoiding DefaultCredentialsError when using google bigquery API
问题描述
我正在尝试在一些bigquery表上执行SQL查询.尝试实例化bigquery客户端对象时,我总是得到DefaultCredentialsError
.例如,通过执行以下操作:
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')
或执行以下操作:
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)
.json credentals文件是否可能有问题?我创建了一个服务帐户密钥:
Could there be a problem with my .json credentals file? I created a service account key:
还有其他建议吗?
推荐答案
您很可能会遇到错误,使用from_service_account_json
方法.
You are most likely hitting a bug with using the from_service_account_json
method.
相反,尝试通过将GOOGLE_APPLICATION_CREDENTIALS
环境变量导出为描述的此处.
Instead, try using the recommended way of authenticating by exporting the GOOGLE_APPLICATION_CREDENTIALS
environment variable as decribed here.
这篇关于使用Google BigQuery API时避免DefaultCredentialsError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!