Search code examples
pythongoogle-apigoogle-fusion-tablesgoogle-api-python-client

How to pass body with Google APIs Client Library?


I use Google APIs Client Library for Python to work with Fusion Tables API. importRows method here requires to provide the data in the body. How should I do it?

response = service.table().importRows(tableId=TABLE_ID, body='zzz,yyy').execute()

returns the error - Got an unexpected keyword argument "body".


Solution

  • There's a slight subtlety here -- the body of the request should be the Table resource, if you want to update it; the contents (in this case, the rows) should actually be passed as a media upload.

    In the python client, this means you want to pass something in to the media_body argument, not body. You can't just pass a literal string -- you need to wrap the data in either a MediaFileUpload or MediaInMemoryUpload. (For the case here, you want the latter, but if you've got a file with rows on disk, you want the former.)