Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98596
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: corrupt download with urllib2 |
| Date | 2015-11-10 14:20 +0100 |
| Organization | None |
| Message-ID | <mailman.209.1447161643.16136.python-list@python.org> (permalink) |
| References | <n1sq82$k3g$1@news2.informatik.uni-stuttgart.de> |
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, 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/download/7za.exe"
>
> try:
> szo = open(sz,'w')
Open the file in binary mode to avoid the translation of "\n" into "\r\n":
szo = open(sz, 'wb')
> except (IOError,OSError) as e:
> die('cannot write %s - %s' % (sz,e.strerror))
Unrelated, but I recommend that you let the exceptions bubble up for easier
debugging.
Python is not Perl ;)
> 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()))
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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