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


Groups > comp.lang.python > #93376

Re: Python 3 resuma a file download

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 <ian.g.kelly@gmail.com>
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 <ef677bbd-5b40-40b7-8f56-e6a7d39f9ce0@googlegroups.com>
References <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> <mailman.204.1435707788.3674.python-list@python.org> <ef677bbd-5b40-40b7-8f56-e6a7d39f9ce0@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 1 Jul 2015 09:10:15 -0600
Subject Re: Python 3 resuma a file download
To Python <python-list@python.org>
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 <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.219.1435763456.3674.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Wed, Jul 1, 2015 at 8:18 AM,  <zljubisic@gmail.com> 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.

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