Search code examples
pythonurllib

Python Download - file corrupted?


Hi so im building a script which downloads a .exe file via urllib. Sadly,the downloaded file, when executed, shows an error prompt by windows, the file would be damaged or corrupted and cannot be executed.

My script:

url = 'https://anonfiles.com/51l035B5x5/npp.8.1.9.3.Installer.x64_exe'

f = urllib.request.urlopen(url)
file = f.read()
f.close()
f2 = open('npp.exe', 'wb')
f2.write(file)
f2.close()

how to proceed so the file is working when downloaded?


Solution

  • Try downloading it like this instead:

    import urllib.request
    urllib.request.urlretrieve("https://anonfiles.com/51l035B5x5/npp.8.1.9.3.Installer.x64_exe", "npp.exe")
    

    If that doesn't work, the executable might be broken itself.