I want to read a file on internet from a particular offset in python. Like in normal file handler (return by open()) we have a seek() api. Is there any way of doing this when reading from network.
import urllib.request
g = urllib.request.urlopen('http://tools.ietf.org/rfc/rfc2822.txt')
g.seek(20)
f=g.read(100)
print(f)
I tried the following but it obviosuly gave error
io.UnsupportedOperation: seek
What can I do to solve this?
You can use
Range
header (only if the server supports it):But not all server support
Range
. You should check response header. If server does not support it, you should skip bytes by read them.