Re: Python 3 resuma a file download

2015-07-04 Thread zljubisic
I have a working solution. :) The function below will download a file securely. Thank anyone who helped. I wouldn't be able to write this function without your help. I hope, someone else will benefit from our united work. Best regards. import os import urllib.request def Download(rfile, lfile):

Re: Python 3 resuma a file download

2015-07-02 Thread MRAB
On 2015-07-02 21:27, zljubi...@gmail.com wrote: This is my final version which doesn't work. :( Actually, it works with another file on another server, but doesn't work with mp4 files on this particular server. I really don't know what to do? Regards. import os import urllib.request def Down

Re: Python 3 resuma a file download

2015-07-02 Thread Irmen de Jong
On 2-7-2015 22:27, zljubi...@gmail.com wrote: > This is my final version which doesn't work. :( > Actually, it works with another file on another server, but doesn't work with > mp4 files on this particular server. > > I really don't know what to do? Do you really need to download these files us

Re: Python 3 resuma a file download

2015-07-02 Thread zljubisic
This is my final version which doesn't work. :( Actually, it works with another file on another server, but doesn't work with mp4 files on this particular server. I really don't know what to do? Regards. import os import urllib.request def Download(rfile, lfile): retval = False if os

Re: Python 3 resuma a file download

2015-07-01 Thread Tim Chase
On 2015-07-01 21:51, Peter Otten wrote: > use a loop: > > CHUNKSIZE = 16*1024 # for example > while True: >data = response.read(CHUNKSIZE) >if not data: >break >out_file.write(data) > > > This can be simplified: > > shutil.copyfileobj(response, out_file) It's these little

Re: Python 3 resuma a file download

2015-07-01 Thread Cameron Simpson
On 01Jul2015 21:51, Peter Otten <__pete...@web.de> wrote: zljubi...@gmail.com wrote: But how to read chunks? Instead of data = response.read() # a `bytes` object out_file.write(data) use a loop: CHUNKSIZE = 16*1024 # for example while True: data = response.read(CHUNKSI

Re: Python 3 resuma a file download

2015-07-01 Thread Peter Otten
zljubi...@gmail.com wrote: > New version with chunks: > > import os > import urllib.request > > def Download(rfile, lfile): > > retval = False > > if os.path.isfile(lfile): > lsize = os.stat(lfile).st_size > else: > lsize = 0 > > req = urllib.request.Request(rf

Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
New version with chunks: import os import urllib.request def Download(rfile, lfile): retval = False if os.path.isfile(lfile): lsize = os.stat(lfile).st_size else: lsize = 0 req = urllib.request.Request(rfile) req.add_header('Range', "bytes={}-".format(lsize)

Re: Python 3 resuma a file download

2015-07-01 Thread Peter Otten
zljubi...@gmail.com wrote: > But how to read chunks? Instead of > data = response.read() # a `bytes` object > out_file.write(data) use a loop: CHUNKSIZE = 16*1024 # for example while True: data = response.read(CHUNKSIZE) if not data: break out_file.write(data)

Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
But how to read chunks? -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 resuma a file download

2015-07-01 Thread Chris Angelico
On Thu, Jul 2, 2015 at 5:24 AM, wrote: > with urllib.request.urlopen(req) as response, open(lfile, 'ab') as > out_file: > data = response.read() # a `bytes` object > out_file.write(data) > If a file is big enough to want to resume the download once, you almost certainly want

Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
Currently I am executing the following code: import os import urllib.request def Download(rfile, lfile): retval = False if os.path.isfile(lfile): lsize = os.stat(lfile).st_size else: lsize = 0 req = urllib.request.Request(rfile) req.add_header('Range', "byte

Re: Python 3 resuma a file download

2015-07-01 Thread Ian Kelly
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.Reque

Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
On Wednesday, 1 July 2015 01:43:19 UTC+2, Cameron Simpson wrote: > On 30Jun2015 08:34, 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.urlre

Re: Python 3 resuma a file download

2015-06-30 Thread Cameron Simpson
On 30Jun2015 08:34, 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 (

Python 3 resuma a file download

2015-06-30 Thread zljubisic
Hi, 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 exce