Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python seek on remote file using HTTP

Tags:

python

http

seek

How do I seek to a particular position on a remote (HTTP) file so I can download only that part?

Lets say the bytes on a remote file were: 1234567890

I wanna seek to 4 and download 3 bytes from there so I would have: 456

and also, how do I check if a remote file exists? I tried, os.path.isfile() but it returns False when I'm passing a remote file url.

like image 353
Marconi Avatar asked Dec 28 '09 19:12

Marconi


1 Answers

You can use httpio to access remote HTTP files as if they were local:

pip install httpio
import zipfile
import httpio

url = "http://some/large/file.zip"
with httpio.open(url) as fp:
    zf = zipfile.ZipFile(fp)
    print(zf.namelist())
like image 159
Martin Valgur Avatar answered Oct 11 '22 01:10

Martin Valgur