Closed GabrielVidal1 closed 2 days ago
Hi @GabrielVidal1 The docs need to be updated, the server returns a bytes stream so you should write the files as bytes and then decode later. So something like this will work
output_file = client.files.download(file_id=file_id)
with open(output_path, "wb") as f:
for chunk in output_file.stream:
f.write(chunk)
If you don't do this then there's a chance you land on a chunk with an incomplete bytes sequence which will raise the error that you see
If you want to only write a decoded file then you could use an incremental decoder that will handle buffering for you (the codecs
module has an implementation I believe)
Hi @jean-malo,
Thanks for your quick response! Writing the file as bytes and decoding it later works for me 👍
Python -VV
Pip Freeze
Reproduction Steps
Using mainly parts of the example script provided to use the batch API (found here) I get an error as the
output_file
indownload_file
is not complete with all responses.Restarting the download process of the batch result a second time works as expected.
Here are the 3 functions from the example I used with a input_file of ~4000 samples
With ~4500 samples, the jobs completes without errors, but I get the following error from the
download_file
file function :After checking the downloaded file at batch_job.output_file I find that the file stops unexpectedly at the ~2000 line:
Expected Behavior
I expect to be able to download the complete result file of a batch with the provided function, without any errors.
Additional Context
No response
Suggested Solutions
This problem seems to happen once every 2-3 tries, so should I just add a small delay (eg 5s) before trying to download the results of a batch to ensure having a full file ?