fixed py3 exception handling