In the process of creating an auto-updater for my program, and I'm having trouble successfully downloading an .exe file.
What I was doing was something like this:
import urllib
url = '--insert-url--'
f = urllib.urlopen(url)
file = f.read()
f.close
f2 = open('download.exe', 'w')
f2.write(file)
f2.close
I encountered no errors while downloading, but when I try to run the execution, I get the following error:
The version of this file is not compatable with the version of Windows you're running. Check your computer's system information to see whether you need an x86(32-bit) or an x64 (64-bit) version of the program, and then contact the software publisher.
I uploaded the execution myself and it worked fine before.
I also tried some various other methods for downloading that I found, which resulted in the same error, and I also tried uploading to different sites to make sure that wasn't it.
Is there a special way I need to do this?
EDIT:
I did some further testing with the download. I ran the program (I'm using what Spencer posted now) on a different computer -- a 32-bit system. (Mine is a 64-bit.) I don't get the error on that computer, but when I run the program, the command line comes up, as it is a command-line style .exe that I'm using as my test download, but the blinking white entry bar thing just bounces all over the place before I have to end the program, so something is obviously getting corrupted.
Also, would the downloading process be possible with a Batch file? This would almost be easier as the program is going to have to restart to begin using the new update anyway, as it is using an entirely new .exe. (I'm going to use py2exe for making the program an .exe.)
According to the official python docs for urllib:
One caveat: the read() method, if the size argument is omitted or negative, may not read until the end of the data stream; there is no good way to determine that the entire stream from a socket has been read in the general case.
an alternative from the same library would be
import urllib
url = '--insert-url--'
filename = 'download.exe'
urllib.urlretrieve(url, filename)