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


Groups > comp.lang.python > #93452

Re: Python 3 resuma a file download

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:Python': 0.05; 'chunk': 0.07; 'subject:file': 0.07; 'raised,': 0.09; 'req': 0.09; 'def': 0.14; 'server,': 0.15; '100))': 0.16; '1024)': 0.16; 'chunk:': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'skip:{ 30': 0.16; 'subject:download': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'skip:u 30': 0.18; 'try:': 0.22; 'file.': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; "doesn't": 0.28; 'appending': 0.29; 'restart': 0.29; 'reset': 0.29; 'server.': 0.30; "skip:' 10": 0.30; 'skip:u 20': 0.30; 'too.': 0.30; 'work.': 0.30; 'received:84': 0.32; 'another': 0.34; 'file': 0.34; 'to:addr :python-list': 0.35; 'false': 0.35; 'really': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'except': 0.36; 'should': 0.37; 'subject:: ': 0.37; 'version': 0.38; 'skip:p 20': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:u 10': 0.62; 'email addr:gmail.com': 0.64; 'regards.': 0.67; 'actually,': 0.84; 'mp4': 0.84; 'url:hr': 0.84; 'url:video': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=OoyysHLt c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=AGkejYDSTmIA:10 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=PmasVLyhAAAA:8 a=_oFeDEyMIB-hGXyuoHUA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett@:2500
Date Thu, 02 Jul 2015 23:07:39 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Python 3 resuma a file download
References <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> <mailman.204.1435707788.3674.python-list@python.org> <ef677bbd-5b40-40b7-8f56-e6a7d39f9ce0@googlegroups.com> <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> <mn1gct$nb0$1@ger.gmane.org> <mailman.232.1435805143.3674.python-list@python.org> <e37f20c5-1baf-48fa-a5c7-762616d18e5c@googlegroups.com>
In-Reply-To <e37f20c5-1baf-48fa-a5c7-762616d18e5c@googlegroups.com>
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.262.1435874866.3674.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1435874866 news.xs4all.nl 2884 [2001:888:2000:d::a6]:44149
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93452

Show key headers only | View raw


On 2015-07-02 21:27, zljubisic@gmail.com wrote:
> This is my final version which doesn't work. :(
> Actually, it works with another file on another server, but doesn't work with mp4 files on this particular server.
>
> I really don't know what to do?
>
> Regards.
>
> 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)
>
>      rfsize = urllib.request.urlopen(req).length
>
>      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(64 * 1024)
>                  # chunk = response.read(128)
>                  if not chunk: break
>                  out_file.write(chunk)
>                  out_file.flush()
>
>
>                  lfsize = os.stat(lfile).st_size
>
>                   print("{0:.2f}".format(lfsize / rfsize * 100))
>              except ConnectionResetError as e:
>                  print('Exception ConnectionResetError {0}'.format(os.stat(lfile).st_size))
>                  response = urllib.request.urlopen(req)
>
>
>      if lfsize == rfsize:
>          retval = True
>
>      return retval
>
>
> while not Download('http://video.hrt.hr/2906/otv296.mp4', 'otv296.mp4'):
>      print('1')
>
If a ConnectionResetError is raised, it'll restart the request from the
beginning, but continue appending to the same file. You should reset
the writing too.

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