문제

Code excerpt:

file = open("D:\\DownloadFolder\\test.jpg", "wb")
def callback(data):
    file.write(data)

connect.retrbinary('RETR cover.jpg', callback)
print("completed")

This script downloads the file cover.jpg from my server. The image is returned distorted though (some parts are missing.) Any ideas?

도움이 되었습니까?

해결책

You are writing files, but not closing them. Consider closing the file with file.close():

file = open("D:\\DownloadFolder\\test.jpg", "wb")
def callback(data):
    file.write(data)

connect.retrbinary('RETR cover.jpg', callback)
file.close()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top