问题
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?
回答1:
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')
来源:https://stackoverflow.com/questions/43459125/uploading-excel-files-to-dropbox