Skip to main content

Malformed file when downloading xlsx file with python sdk

  • May 31, 2023
  • 1 reply
  • 173 views

rbarbosa Box

Got an interesting question from a developer:



I am accessing box to download an xlsx file, the file gets downloaded, yet it is corrupted, may you help ? thanks in advance


file_id = '1234'



download_file = client.file(file_id).get()

transfer_file = open("/home/wsuser/work/" + download_file.name, 'wb')

download_file.download_to(transfer_file)

1 reply

rbarbosa Box
  • Author
  • Developer Advocate
  • 553 replies
  • May 31, 2023

Hi Massimo,


Python open does not close the file automatically, and I suspect it is why your file is getting corrupted.


Try it like this:


file_id = '1234'



download_file = client.file(file_id).get()

with open("/home/wsuser/work/" + download_file.name, 'wb') as transfer_file:

    download_file.download_to(transfer_file)


The with statement will close the file once the download is done.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings