I am accessing some .mat files hosted on a SimpleHTTP server and trying to load them using Python's loadmat:
from scipy.io import loadmat
import requests
r = requests.get(requestURL,stream=True)
print loadmat(r.raw)
However, I am getting an error
io.UnsupportedOperation: seek
After looking around it seems that r.raw is a file object which is not seekable, and therefore I can't use loadmat on it. I tried the solution here (modified slightly to work with Python 2.7), but maybe I did something wrong because when I try
seekfile = SeekableHTTPFile(requestURL,debug=True)
print 'closed', seekfile.closed
It tells me that the file is closed, and therefore I can't use loadmat on that either. I can provide the code for my modified version if that would be helpful, but I was hoping that there is some better solution to my problem here.
I can't copy/download the .mat file because I don't have write permission on the server where my script is hosted. So I'm looking for a way to get a seekable file object that loadmat can use.
Edit: attempt using StringIO
import StringIO
stringfile = StringIO.StringIO()
stringfile.write(repr(r.raw.read())) # repr needed because of null characters
loaded = loadmat(stringfile)
stringfile.close()
r.raw.close()
results in:
ValueError: Unknown mat file type, version 48, 92