I am using Google APIs Client Library for Python to update a Fusion Table and add rows to a Fusion Table with the Fusion Tables API v1. I can do this successfully when I do it one row at a time using the SQL INSERT query method. I would also like to be able to update the Fusion Table using the importRows
method.
I start with a file 'testCsv.csv' and would like to import it completely into an existing Fusion Table. There is a good conceptual explanation of doing this here.
The conceptual example explains if the API accepted images, but to update a Fusion Table, the type must be 'application/octet-stream'.
I have tried to use the importRows
method with the following code (note: service
is an authenticated API connection):
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
.
.
.
mediaCsv=MediaFileUpload(csvFileName, mimetype='application/octet-stream')
request = service.table().importRows(tableId=wrrTweetsID, media_body=mediaCsv,
startLine=1, encoding='auto-detect')
response = request.execute()
When I execute this code I get back this error message:
raise HttpError(resp, content, uri=self.uri)
apiclient.errors.HttpError: <HttpError 500 when requesting
"https://www.googleapis.com/upload/fusiontables/v1/tables/--table_id--/import?uploadType=media&alt=json&startLine=1&encoding=auto-detect"
returned "Backend Error">
My question is, do I need to do something to the .csv
to convert it to application/octet-stream
? Or is there something else I am missing in using this method?