2017-04-17 131 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')