Fix old exception syntax that breaks Python 3 compatibility