0

I try to do streaming inserts into a bigquery table and get the http 500 error "Unexpected. Please try again". What am I doing wrong?

credentials =AppAssertionCredentials(scope='https://www.googleapis.com/auth/bigquery')
http = credentials.authorize(httplib2.Http(memcache))
service = build('bigquery', 'v2', http=http)
self.tabledata = service.tabledata()
body = '{"rows": [{"json": {"userid": 1, "client": 1, "type": 1, "time": 0.0}}]}'
response = self.tabledata.insertAll(projectId=PROJECT_ID, datasetId='hunter', tableId='test', body=body).execute()

The stack trace I get is:

2013-10-24 09:49:58.167 Encountered unexpected error from ProtoRPC method implementation: HttpError (<HttpError   500 when requesting https://www.googleapis.com/bigquery/v2/projects/avalanche-test/datasets/hunter/tables/test/insertAll?alt=json returned "Unexpected. Please try again.">)
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
response = method(instance, request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/endpoints-1.0/endpoints/api_config.py", line 1321, in invoke_remote
return remote_method(service_instance, request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/remote.py", line 412, in invoke_remote_method
response = method(service_instance, request)
File "/base/data/home/apps/s~avalanche-test/1.371139085360971734/main.py", line 27, in trackLogin
self.track(evt)
File "/base/data/home/apps/s~avalanche-test/1.371139085360971734/main.py", line 22, in track
resp = logging.info(self.helper.insertEvent(evt))
File "/base/data/home/apps/s~avalanche-test/1.371139085360971734/bigquery.py", line 27, in insertEvent
response = self.tabledata.insertAll(projectId=PROJECT_ID, datasetId='hunter', tableId='test', body=body).execute()
File "/base/data/home/apps/s~avalanche-test/1.371139085360971734/oauth2client/util.py", line 132, in positional_wrapper
return wrapped(*args, **kwargs)
File "/base/data/home/apps/s~avalanche-test/1.371139085360971734/apiclient/http.py", line 723, in execute
raise HttpError(resp, content, uri=self.uri)
HttpError: <HttpError 500 when requesting https://www.googleapis.com/bigquery/v2/projects/avalanche-test/datasets/hunter/tables/test/insertAll?alt=json returned "Unexpected. Please try again."> 
4

1 回答 1

2

我认为问题在于您将 JSON 编码的字符串作为正文传递。

正文应该是 JSON 结构的 python 等价物。所以调用应该是这样的:

response = self.tabledata.insertAll(projectId=PROJECT_ID, datasetId='hunter', tableId='test', body={rows: [{json: {userid: 1, client: 1, type: 1, time: 0.0}}, ...]}).execute()
于 2013-10-24T18:24:32.037 回答