Python convert StringIO to binary

Viewed 4842

I have a simple task: in luigi, store pandas dataframe as a csv in dropbox, using dropbox-python sdk

Usually (with S3, for example) you can use StringIO as a file-like in-memory object. It also works great with pandas df.to_csv()

Unfortunately, dropbox sdk requires binary type, and I can't get how to translate StringIO into binary:

with io.StringIO() as f:
    DF.to_csv(f, index=None)
    self.client.files_upload(f, path=path, mode=wmode)

TypeError: expected request_binary as binary type, got <class '_io.StringIO'>

ByteIO won't work with the df.to_csv() ...

1 Answers
Related