Uploading Excel files to dropbox?

北城余情 提交于 2019-12-24 07:29:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!