Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.91.MISMATCH!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'append': 0.07; 'subject:file': 0.07; 'mode,': 0.09; 'overwrite': 0.09; 'req': 0.09; 'rfc': 0.09; 'wed,': 0.15; 'file,': 0.15; 'formatting,': 0.16; 'subject:download': 0.16; 'url.': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'string': 0.17; 'bytes': 0.18; 'skip:u 30': 0.18; 'skip:" 30': 0.20; 'function,': 0.22; 'pass': 0.22; 'am,': 0.23; '2015': 0.23; 'file.': 0.24; 'header:In-Reply- To:1': 0.24; 'downloaded': 0.24; 'header': 0.24; 'example': 0.25; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'this.': 0.28; 'rest': 0.28; 'correct': 0.29; "skip:' 10": 0.30; 'skip:u 20': 0.30; 'e.g.': 0.31; 'returned': 0.32; 'open': 0.33; 'file': 0.34; 'received:google.com': 0.34; 'to:addr:python-list': 0.35; 'should': 0.37; 'subject:: ': 0.37; 'correctly': 0.37; 'rather': 0.38; 'to:addr:python.org': 0.39; 'data': 0.40; 'build': 0.40; 'sure': 0.40; 'your': 0.60; '500': 0.63; 'jul': 0.72; 'to:name:python': 0.84; 'url:hr': 0.84; 'url:video': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=XKSy4U0YiAph9Bs/5oZ9Ec81iTasktlHsJMSuQpKezk=; b=ia/x7uOiBKObueLvdxDG5Cstb+czlhdQm0/Mtz8LK1kcf2KXYpJBTZMZ7clyjwBasZ HTaQAuD+hn7KAQsq36lkINdIFL1F8BAc42Vh18rBGiDPxXF2wTpb/sZ6l+KmN7/0cmL9 MpdLEo8/oSirgMMCVK55OnYcrdIC7ocUUXkhKiT87sMyxFuZSJc8MgG95Qis0EdHvYuh Hje6RNxukx+4k9jgOGuwxL592fz4JSfl+C4tjBdhh1sVVo5IE7Jhozim9K0JK6GXQIT9 CLBxMNCbZzQS3fjsYAWvJKvl782liDTigYhHbBChCkGdAPxG2nAGP0+fSxDtd3KahF3T UcNQ== X-Received: by 10.170.42.85 with SMTP id 82mr33151745ykk.18.1435763454926; Wed, 01 Jul 2015 08:10:54 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> From: Ian Kelly Date: Wed, 1 Jul 2015 09:10:15 -0600 Subject: Re: Python 3 resuma a file download To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435763456 news.xs4all.nl 2829 [2001:888:2000:d::a6]:47402 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93376 On Wed, Jul 1, 2015 at 8:18 AM, wrote: > if I understood you correctly (I am not sure about which example you are refering), I should do the following: > 1. check already downloaded file size in bytes = downloaded > 2. url = 'http://video.hrt.hr/2906/otv296.mp4' > 3. req = urllib.request.Request(url) > 4. req.add_header('Range', downloaded) You need to use the correct format for the Range header; see RFC 7233. If you have 500 bytes and want the rest of the file, then the value for the Range header would be "bytes=500-", not just "500". You can build that string using string formatting, e.g. "bytes={}-".format(downloaded) > 5. urllib.request.urlretrieve(url, 'otv296.mp4') A couple of problems with this. One is that it doesn't use the Request object that you just constructed, so it wouldn't pass the Range header. The other is that it will overwrite that file, not append to it. You should use the urllib.request.urlopen function, and pass it the Request object rather than the URL. You can then open your local file in append mode, read the file data from the HTTPResponse object returned by urlopen, and write it to the local file.