[PATCH] python: fix error handling