import requests
import tempfile
from scipy.io import loadmat
# Location of the matrix data file
DATA_FILE = "https://orion.math.iastate.edu/lhogben/m407507proj1matrices.mat"
# Temporary file to store the matrix data in
tf = tempfile.TemporaryFile()
loaded_mats = None
try:
# Stream the data into the temporary file
resp = requests.get(DATA_FILE, stream=true)
for chunk in resp.iter_content():
tf.write(chunk)
# Load the matrices from the temporary file
loaded_mats = loadmat(tf)
except Exception as e:
print "An error occurred"
print e
finally:
tf.close()