Improve exception in python scripts