Proper python error handling