错误403:在Python库上运行BigQuery同步查询时响应太大

2024-06-16 11:18:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Python客户机库在googlebigquery中运行一个简单的SELECT同步查询。我得到以下错误:

*** google.cloud.exceptions.Forbidden: 403 Response too large to return. Consider setting allowLargeResults to true

我使用run_sync_query()来达到这个目的。在

我的做法是(去掉不必要的东西):

def run_query(query_str):
    from google.cloud import bigquery
    client = biquery.Client()
    query = client.run_sync_query(query_str)
    query.run()
    return query.fetch_data()

我知道在API documentation中有一个参数allowLargeResults,但我不知道如何从客户端库设置该参数。在


Tags: torunclientcloud参数客户returngoogle
1条回答
网友
1楼 · 发布于 2024-06-16 11:18:51

您可以这样设置:

query.allow_large_results = True

https://github.com/GoogleCloudPlatform/google-cloud-python/blob/e716fbef3dc74e8853346426af356bad364f6637/bigquery/google/cloud/bigquery/job.py#L1090

但是,如果设置allow_large_results,则还必须指定要将结果写入的目标表:

https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query.allowLargeResults

[Optional] If true and query uses legacy SQL dialect, allows the query to produce arbitrarily large result tables at a slight cost in performance. Requires destinationTable to be set. For standard SQL queries, this flag is ignored and large results are always allowed. However, you must still set destinationTable when result size exceeds the allowed maximum response size.

相关问题 更多 >