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


Groups > comp.lang.python > #93389

Re: Python 3 resuma a file download

From Peter Otten <__peter__@web.de>
Subject Re: Python 3 resuma a file download
Date 2015-07-01 22:06 +0200
Organization None
References (3 earlier) <mailman.219.1435763456.3674.python-list@python.org> <4a7fae78-276e-42c6-9d84-1fddbeb99853@googlegroups.com> <mailman.225.1435778925.3674.python-list@python.org> <36d1cf6d-9b99-4d38-8f07-83443bcd2f60@googlegroups.com> <482382f0-8ea4-4085-ae73-0d24e4fd8917@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.227.1435781221.3674.python-list@python.org> (permalink)

Show all headers | View raw


zljubisic@gmail.com wrote:

> New version with chunks:
> 
> import os
> import urllib.request
> 
> def Download(rfile, lfile):
> 
>     retval = False
> 
>     if os.path.isfile(lfile):
>         lsize = os.stat(lfile).st_size
>     else:
>         lsize = 0
> 
>     req = urllib.request.Request(rfile)
>     req.add_header('Range', "bytes={}-".format(lsize))
> 
> 
>     response = urllib.request.urlopen(req)
> 
>     with open(lfile, 'ab') as out_file:
>         while True:
>             try:
>                 chunk = response.read(8192)
>                 if not chunk: break
>                 out_file.write(chunk)
>             except ConnectionResetError as e:
>                 print('Exception ConnectionResetError
>                 {0}'.format(os.stat(lfile).st_size))

Catching the exception inside the while-True loop is not a good idea.

>     if response.headers.headers['Content-Length'] ==
>     os.stat(lfile).st_size:
>         retval = True
> 
>     return retval
> 
> Download('http://video.hrt.hr/2906/otv296.mp4',
> 'c:\\Users\\zoran\\hrt\\sync\\otv296.mp4')

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


Thread

Python 3 resuma a file download zljubisic@gmail.com - 2015-06-30 08:34 -0700
  Re: Python 3 resuma a file download Cameron Simpson <cs@zip.com.au> - 2015-07-01 09:21 +1000
    Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 07:18 -0700
      Re: Python 3 resuma a file download Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-01 09:10 -0600
        Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 12:24 -0700
          Re: Python 3 resuma a file download Chris Angelico <rosuav@gmail.com> - 2015-07-02 05:28 +1000
            Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 12:31 -0700
              Re: Python 3 resuma a file download Peter Otten <__peter__@web.de> - 2015-07-01 21:51 +0200
              Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 12:59 -0700
                Re: Python 3 resuma a file download Peter Otten <__peter__@web.de> - 2015-07-01 22:06 +0200
              Re: Python 3 resuma a file download Tim Chase <python.list@tim.thechases.com> - 2015-07-01 15:04 -0500
                Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-02 13:27 -0700
                Re: Python 3 resuma a file download Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-07-02 23:31 +0200
                Re: Python 3 resuma a file download MRAB <python@mrabarnett.plus.com> - 2015-07-02 23:07 +0100
                Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-04 22:31 -0700

csiph-web