python - Http 错误 : 400 Missing Required Parameter while using jobs. query() BQ API

标签 python google-cloud-platform google-bigquery

我在 stack-overflow 中找不到完全相同的问题。抱歉,如果这是一个重复的问题。 我正在使用此代码片段将查询传递给表。

_body = {'_query':'SELECT * FROM `<projectId>.<datasetId>.<tableId>`',
                   'useLegacySql': False,
                   'maxResults': 100                  
                   }

table = _bq.jobs().query(projectId= <projectId>,alt = "json", body = _body).execute()

我正在传递所有必需的参数,因为使用了 jobs.query API ,我收到状态代码 200 和结果,但是在将代码片段集成到 python 程序中时,出现以下错误:

File "D:\Applications\Python27\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper\n return wrapped(*args, **kwargs)\n', ' File "D:\Applications\Python27\lib\site-packages\googleapiclient\http.py", line 842, in execute\n raise HttpError(resp, content, uri=self.uri)\n', 'HttpError: https://www.googleapis.com/bigquery/v2/projects/projectId/queries?alt=json returned "Required parameter is missing">\n']

最佳答案

我认为问题不在于 bq 参数,而在于 execute() 参数。 它应该有 http 参数,您可以在其中提供带有用户凭据的 http 上下文

在应用引擎中你可以做这样的事情

SCOPE='https://www.googleapis.com/auth/bigquery https://www.googleapis.com/auth/cloud-patform '
_http = AppAssertionCredentials(scope=SCOPE).authorize(httplib2.Http(timeout=600))
table = _bq.jobs().query(projectId= <projectId>,alt = "json", body = _body).execute(http=_http)

关于python - Http 错误 : 400 Missing Required Parameter while using jobs. query() BQ API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50585306/

相关文章:

python - 如何从 Google App Engine (python) 启动或停止 Amazon EC2 实例

google-bigquery - 错误 : No matching signature for operator = for argument types: STRUCT<id STRING, 名称 STRING>,STRING。支持的签名:ANY = ANY [4:7]

google-bigquery - 比较 2 个 BigQuery 表中的 2 条记录,有没有办法判断它们是否相同?

java - 使用 Java 从本地驱动器将 JSON 文件上传到 BigQuery

python - 如何测试运行我的代码的机器上是否已经安装了 nltk 资源?

python - 将流数据从 Azure Blob 存储读取到 Databricks 中

python - 用于 Python 的 MySQL 连接器

python - pandas 中是否有相当于 excel 公式的内容

java - 上传到谷歌云存储时输出数据以随机顺序出现

google-cloud-platform - 如何准备 CSV 文件以从 GCP 中提取 AutoML 实体?