fix exception handling under Python 3 with ANSI