I think your file has never been closed: on line 24 of your script load, you opened the destination file to write binary data. Only when you call close() in the same file that the data is pushed from memory to the file (there is also a method for calling without closing the file, but I canβt remember it right now).
In general, it is best to open file objects using the with statement:
with open(os.path.join(destdir,filename), 'wb') as f: shutil.copyfileobj(response, f)
When the with statement is used with file objects, it automatically closes them at the end of the block, if you ever break out of the block, or if the block is left for any other reason (there may be an unhandled exception due to which the interpreter should exit).
If you cannot use the with statement (I think some older versions of Python do not support its use with file objects), you can simply call close () on the object after you finish:
f = open(os.path.join(destdir,filename), 'wb') shutil.copyfileobj(response, f) f.close()
I hope this is the reason, because then it will be a simple fix!
source share