我正在尝试使用POST请求将数据插入BigQuery表。 我的应用程序创建了以指定格式请求的主体:
--xxx
Content-Type: application/json; charset=UTF-8
{
"configuration": {
"load": {
"sourceFormat": "NEWLINE_DELIMITED_JSON"
},
"destinationTable": {
"projectId": "some-id",
"datasetId": "dataset-id",
"tableId": "cards"
}
}
}
--xxx
Content-Type: application/octet-stream
{"board_id":1,"version":2,"card_id":1,"title":"Tytul kartki 1"}
--xxx--
但是当我使用以下方式发送此数据时
credentials = SignedJwtAssertionCredentials(
SERVICE_ACCOUNT_EMAIL,
key,
scope='https://www.googleapis.com/auth/bigquery')
self.http = credentials.authorize(httplib2.Http())
headers = {'Content-Type': 'multipart/related; boundary=xxx'}
resp, content = self.http.request(url, method="POST",
body=output,
headers=headers)
来自服务器的响应是:
Status: {'date': 'Thu, 25 Jul 2013 12:49:06 GMT', 'status': '400', 'content-length': '205', 'content-type': 'application/json', 'server': 'HTTP Upload Server Built on Jul 12 2013 17:12:36 (1373674356)'}
Content: {
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter is missing"
}
],
"code": 400,
"message": "Required parameter is missing"
}
}
我不知道缺少什么参数。只有文档中需要的参数是sourceUris,但我想从请求主体而不是从GS加载数据。
答案 0 :(得分:1)
我认为问题是您缺少架构配置:
'configuration': {
'load': {
'sourceFormat': <required for JSON files>',
'schema': {
'fields': [
{'name':'f1', 'type':'STRING'},
{'name':'f2', type:'INTEGER'}
]
},
'destinationTable': {
'projectId': 'projectId',
'datasetId': 'datasetId',
'tableId': 'tableId'
}
}
}
此链接可能会帮助您:https://developers.google.com/bigquery/loading-data-into-bigquery
答案 1 :(得分:0)
查看loading data page上的示例。请注意,项目ID位于两个位置,包括jobData和destinationTable。这可能是缺少参数错误的原因。
答案 2 :(得分:0)
问题是“destinationTable”必须在“load”对象内:
{
"configuration": {
"load": {
"sourceFormat": "NEWLINE_DELIMITED_JSON"
"destinationTable": {
"projectId": "some-id",
"datasetId": "dataset-id",
"tableId": "cards"
}
}
}
}
可以在Loading Data Into BigQuery页面中看到。