On Wednesday, 1 July 2015 01:43:19 UTC+2, Cameron Simpson wrote: > On 30Jun2015 08:34, zljubi...@gmail.com <zljubi...@gmail.com> wrote: > >I would like to download a file (http://video.hrt.hr/2906/otv296.mp4) > >If the connection is OK, I can download the file with: > > > >import urllib.request > >urllib.request.urlretrieve(remote_file, local_file) > > > >Sometimes when I am connected on week wireless (not mine) network I get > >WinError 10054 exception (windows 7). > > > >When it happens, I would like to resume download instead of doing everything > >from very beginning. > > > >How to do that? > > > >I read about Range header and chunks, but this server doesn't have any > >headers. > > > >What options do I have with this particular file? > > You need to use a Range: header. I don't know what you mean when you say > "this > server doesn't have any headers". All HTTP requests and responses use > headers. > Possibly you mean you code isn't setting any headers. > > What you need to do is separate your call to urlretrieve into a call to > construct a Request object, add a Range header, then fetch the URL using the > Request object, appending the results (if successful) to the end of your > local > file. > > If you go to: > > > https://docs.python.org/3/library/urllib.request.html#urllib.request.urlretrieve > > and scroll up you will find example code doing that kind of thing in the > examples above. > > Cheers, > Cameron Simpson <c...@zip.com.au> > > The British Interplanetary Society? How many planets are members then? > - G. Robb
Hi, 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) 5. urllib.request.urlretrieve(url, 'otv296.mp4') Is that what you were saying? Regards. -- https://mail.python.org/mailman/listinfo/python-list