Search code examples
pythonpandasexport-to-exceldropbox-api

Uploading Excel files to dropbox?


I am trying to upload a file I am creating using ExcelWriter via pandas.

Here is what I have so far:

output = BytesIO()
writer = pd.ExcelWriter(output, engine='xlsxwriter')
df1.to_excel(writer, sheet_name='raw_data', index=False)
df_totals.to_excel(writer, sheet_name='totals', index=False)
writer.save()
output.seek(0)
dbx.files_upload(output, 'my_path/test.xlsx')

It is throwing the error:

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

The file_upload method takes bytes as input so I don't understand?


Solution

  • As you can see in the docs, files_upload expects a bytes object, not a BytesIO object.

    The following should work:

    dbx.files_upload(output.getvalue(), 'my_path/test.xlsx')