从大查询中获取数据时出现凭证错误

时间:2019-04-17 09:34:07

标签: python pandas google-bigquery

我正在尝试使用python从大查询中获取数据。下面是我的代码:

bg_client = bigquery.Client.from_service_account_json("soy-serenity.json")

QUERY = "(SELECT * from table_name)"

df = gbq.read_gbq(QUERY, project_id = 'soy-serenity', dialect = 'standard')

这一直持续到昨天。不知何故,它给出了以下错误:

read_gbq() got an unexpected keyword argument 'credentials'

2 个答案:

答案 0 :(得分:0)

尝试这样:

from google.oauth2 import service_account
import pandas_gbq

credentials = service_account.Credentials.from_service_account_file(
    'soy-serenity.json',
)
sql = "SELECT * from table_name"
df = pandas_gbq.read_gbq(sql, project_id="soy-serenity", credentials=credentials)

答案 1 :(得分:0)

following link显示了一个示例,您可以运行该示例以使用Python从BigQuery中获取数据:

import os
from google.cloud import bigquery

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'path_to_soy-serenity.json'
client = bigquery.Client()

query = ("SELECT * FROM `bigquery-public-data.usa_names.usa_1910_2013`")
query_job = client.query(query, location="US",) 

for row in query_job:  # API request - fetches results
    assert row[0] == row.name == row["name"]
    print(row)