2017-04-17 140 views
1

我想上传一个文件,我使用ExcelWriter通过熊猫创建。上传Excel文件到Dropbox?

这是我到目前为止有:

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

它引发错误:

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

的file_upload方法将字节输入,所以我不明白?

回答

3

正如您在the docs,files_upload中所看到的那样,期望一个字节对象,而不是一个BytesIO对象。

下面应该工作:

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