Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98595

corrupt download with urllib2

From Ulli Horlacher <framstag@rus.uni-stuttgart.de>
Newsgroups comp.lang.python
Subject corrupt download with urllib2
Date 2015-11-10 13:08 +0000
Organization University of Stuttgart, FRG
Message-ID <n1sq82$k3g$1@news2.informatik.uni-stuttgart.de> (permalink)

Show all headers | View raw


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@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/

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

corrupt download with urllib2 Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-10 13:08 +0000
  Re: corrupt download with urllib2 Peter Otten <__peter__@web.de> - 2015-11-10 14:20 +0100
    Re: corrupt download with urllib2 Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-10 13:43 +0000
  Re: corrupt download with urllib2 Peter Otten <__peter__@web.de> - 2015-11-10 14:40 +0100
    Re: corrupt download with urllib2 Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-10 13:59 +0000
      Re: corrupt download with urllib2 Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-10 15:51 +0000
        Re: corrupt download with urllib2 Peter Otten <__peter__@web.de> - 2015-11-10 17:48 +0100
          Re: corrupt download with urllib2 Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-10 17:21 +0000

csiph-web