Improved exception handling in the Python client