Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93376
| 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 | 2015-07-01 09:10 -0600 |
| Subject | Re: Python 3 resuma a file download |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.219.1435763456.3674.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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