4

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?

tehhowch
  • 9,645
  • 4
  • 24
  • 42
hodgemm
  • 81
  • 4

1 Answers1

4

Since posting this question, I have learned that application/octet-stream is similar to saying that the type is anything. I have also figured out what was wrong with my use of importRows. The method documentation indicates that

"Default is UTF-8. Use 'auto-detect' if you are unsure of the encoding."

I assumed that using 'auto-detect' was the safest way to make sure my request was received correctly. That was an incorrect assumption: changing the encoding to be 'utf-8' resulted in a successful importRows request.

tehhowch
  • 9,645
  • 4
  • 24
  • 42
hodgemm
  • 81
  • 4