python: Raise exceptions on write errors.