corrupt download with urllib2
Ulli Horlacher
framstag at rus.uni-stuttgart.de
Tue Nov 10 08:08:18 EST 2015
I am currently developing a program which should run on Linux and Windows.
Later it shall be compiled with PyInstaller. Therefore I am using Python 2.7
My program must download http://fex.belwue.de/download/7za.exe
I am using this code:
sz = path.join(fexhome,'7za.exe')
szurl = "http://fex.belwue.de/download/7za.exe"
try:
szo = open(sz,'w')
except (IOError,OSError) as e:
die('cannot write %s - %s' % (sz,e.strerror))
import urllib2
printf("\ndownloading %s\n",szurl)
try:
req = urllib2.Request(szurl)
req.add_header('User-Agent',useragent)
u = urllib2.urlopen(req)
except urllib2.URLError as e:
die('cannot get %s - %s' % (szurl,e.reason))
except urllib2.HTTPError as e:
die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason))
if u.getcode() == 200:
print(u.read(),file=szo,end='')
szo.close()
else:
die('cannot get %s - server reply: %d' % (szurl,u.getcode()))
It works with Linux, but not with Windows 7, where the downloaded 7za.exe is
corrupt: it has the wrong size, 589044 instead of 587776 Bytes.
Where is my error?
--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-68565868
Allmandring 30a Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/
More information about the Python-list
mailing list