[Tutor] Request Module Corrupts Zip File

Nathan Prince nathanprince121 at gmail.com
Mon May 18 16:36:23 EDT 2020


Why does a downloaded zip file using requests end up corrupted? Trying to make a program that starts a download a specified time.

Code:

import requests
import time
import datetime

tim = datetime.datetime.now()
print("########So Far Only Works With mp4, png, jpg, pkg and exe files########")
time.sleep(1)
DLTime = input("Time\nHH:MM\n")
url = input("URL:\n")
Location = ("/Users/jenniferprince/Downloads/" + input("File Name\n"))
print("Waiting...")

while(True):
    tim = datetime.datetime.now()
    if tim.strftime("%H:%M") == DLTime:
        print("Download Started")
        myfile = requests.get(url)
        open(Location, 'wb').write(myfile.content)
        print("\nDownload Finished")
        input("Press Enter To Finish")
        exit()
    time.sleep(1)

Note: Had to use tim not time due to interference with other parts of code.


More information about the Tutor mailing list