Fix error handling for python api wrapper

The title says it all.