Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.05; 'that?': 0.05; 'subject:file': 0.07; 'fetch': 0.09; 'skip:> 40': 0.09; '"this': 0.13; 'exception': 0.13; '(windows': 0.16; 'beginning.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'headers.': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'simpson': 0.16; 'subject:download': 0.16; 'then?': 0.16; 'url:urllib': 0.16; 'wrote:': 0.16; 'examples': 0.18; '(not': 0.20; 'cheers,': 0.24; 'file.': 0.24; 'header:In-Reply-To:1': 0.24; 'header': 0.24; 'example': 0.25; 'header:User-Agent:1': 0.26; 'requests': 0.26; 'connected': 0.27; 'separate': 0.27; 'object,': 0.27; 'options': 0.28; "doesn't": 0.28; 'appending': 0.29; 'header,': 0.29; 'connection': 0.30; 'code': 0.31; 'possibly': 0.32; 'url:python': 0.33; 'http': 0.33; 'file': 0.34; 'add': 0.34; 'server': 0.34; 'to:addr:python-list': 0.35; "isn't": 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'setting': 0.37; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'ok,': 0.37; 'instead': 0.38; 'say': 0.38; 'doing': 0.38; 'mean': 0.38; 'end': 0.39; 'url:docs': 0.39; 'to:addr:python.org': 0.39; 'url:3': 0.60; 'content- disposition:inline': 0.60; 'your': 0.60; 'skip:u 10': 0.62; 'email addr:gmail.com': 0.64; 'results': 0.66; 'cameron': 0.66; 'received:61': 0.72; '>how': 0.84; '>if': 0.84; 'construct': 0.84; 'planets': 0.84; 'url:hr': 0.84; 'british': 0.88; 'url:video': 0.91; 'responses': 0.93 X-Authentication-Info: Submitted using ID cskk@bigpond.com X-Authority-Analysis: v=2.0 cv=F6HVh9dN c=1 sm=1 a=j2sYrfh2hMMhR38WiyXXxg==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=yEdEr6MRgwAA:10 a=zOBTXjUuO1YA:10 a=pGLkceISAAAA:8 a=PmasVLyhAAAA:8 a=8AHkEIZyAAAA:8 a=OrNv4poWuEsDkW4GhKUA:9 a=CjuIK1q_8ugA:10 a=0cVBhQSWoL8A:10 a=j2sYrfh2hMMhR38WiyXXxg==:117 Date: Wed, 1 Jul 2015 09:21:52 +1000 From: Cameron Simpson To: python-list@python.org Subject: Re: Python 3 resuma a file download MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> User-Agent: Mutt/1.5.23 (2014-03-12) References: <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435707788 news.xs4all.nl 2859 [2001:888:2000:d::a6]:35101 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93355 On 30Jun2015 08:34, zljubisic@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 The British Interplanetary Society? How many planets are members then? - G. Robb