Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Peter Otten <__pete...@web.de> wrote: > > I have a problem with it: There is no feedback for the user about the > > progress of the transfer, which can last several hours. > > > > For small files shutil.copyfileobj() is a good idea, but not for huge > > ones. > > Indeed. Have a look at the sourc

Re: corrupt download with urllib2

2015-11-10 Thread Peter Otten
Ulli Horlacher wrote: > Ulli Horlacher wrote: >> Peter Otten <__pete...@web.de> wrote: > >> > - consider shutil.copyfileobj to limit memory usage when dealing with >> > data >> > of arbitrary size. >> > >> > Putting it together: >> > >> > with open(sz, "wb") as szo: >> > shutil.c

Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Ulli Horlacher wrote: > Peter Otten <__pete...@web.de> wrote: > > - consider shutil.copyfileobj to limit memory usage when dealing with data > > of arbitrary size. > > > > Putting it together: > > > > with open(sz, "wb") as szo: > > shutil.copyfileobj(u, szo) > > This writes the

Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Peter Otten <__pete...@web.de> wrote: > Ulli Horlacher wrote: > > > if u.getcode() == 200: > > print(u.read(),file=szo,end='') > > szo.close() > > else: > > die('cannot get %s - server reply: %d' % (szurl,u.getcode())) > > More random remarks: Always welcome - I am here

Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Peter Otten <__pete...@web.de> wrote: > > 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? > > > sz = path.join(fexhome,'7za.exe') > > szurl = "http://fex.belwue.de

Re: corrupt download with urllib2

2015-11-10 Thread Peter Otten
Ulli Horlacher wrote: > if u.getcode() == 200: > print(u.read(),file=szo,end='') > szo.close() > else: > die('cannot get %s - server reply: %d' % (szurl,u.getcode())) More random remarks: - print() gives the impression that you are dealing with text, and using it with

Re: corrupt download with urllib2

2015-11-10 Thread Peter Otten
Ulli Horlacher wrote: > 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: > It works with Linux,