Better error checking for python