Python BigQuery查询响应';作业完成';:假的

Python BigQuery查询响应';作业完成';:假的,python,python-2.7,google-bigquery,Python,Python 2.7,Google Bigquery,我有以下功能: def query_big_query(query_data, project_id): credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials_bq.json') bigquery_service = build('bigquery', 'v2', credentials=credentials) try: query_request = bi

我有以下功能:

def query_big_query(query_data, project_id):
    credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials_bq.json')
    bigquery_service = build('bigquery', 'v2', credentials=credentials)
    try:
        query_request = bigquery_service.jobs()
        query_response = query_request.query(projectId=project_id, body=query_data).execute()
        return query_response
    except HttpError as error:
        print ('Error :{}'.format(error.content))
        raise error
但是,有些查询不返回数据,因为查询需要一些时间,因此返回以下字符串:

{u'kind': u'bigquery#queryResponse', u'jobComplete': False, u'jobReference': {u'projectId': u'od', u'jobId': u'job_5wAuC'}}
我怎样才能等到工作完成(真的)?或者我应该以不同的方式请求结果吗?

试试以下方法:

response = bigquery_service.jobs().getQueryResults(projectId=my_project_id, jobId=my_job_id).execute()
while not response['jobComplete']:
    print "waiting for response..."
    time.sleep(1)
    response = bigquery_service.jobs().getQueryResults(projectId=my_project_id, jobId=my_job_id).execute()
return response
试试这个:

response = bigquery_service.jobs().getQueryResults(projectId=my_project_id, jobId=my_job_id).execute()
while not response['jobComplete']:
    print "waiting for response..."
    time.sleep(1)
    response = bigquery_service.jobs().getQueryResults(projectId=my_project_id, jobId=my_job_id).execute()
return response
尝试在正文中指定更大的timeoutMs,如:

query\u response=query\u request.query(projectd=project\u id,body={'query':您的查询'timeoutMs':180000})。execute()

默认情况下,超时为10000,即10秒

参考资料:

尝试在正文中指定更大的超时,如:

query\u response=query\u request.query(projectd=project\u id,body={'query':您的查询'timeoutMs':180000})。execute()

默认情况下,超时为10000,即10秒

参考: