How to pass body with Google APIs Client Library?

2019-09-03 07:34发布

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".

1条回答
太酷不给撩
2楼-- · 2019-09-03 08:19

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.)

查看更多
登录 后发表回答