【问题标题】:Credential error while fetching data from big query从大查询中获取数据时出现凭据错误
【发布时间】:2019-04-17 09:34:07
【问题描述】:

我正在尝试使用 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'

【问题讨论】:

    标签: python pandas google-bigquery


    【解决方案1】:

    试试这样:

    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)
    

    【讨论】:

    • 你进口的是什么?
    【解决方案2】:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-13
      • 2020-09-15
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      相关资源
      最近更新 更多