简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM