spitfiredd
spitfiredd

Reputation: 3135

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?

Upvotes: 1

Views: 1066

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43246

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

Upvotes: 3

Related Questions