Fix exceptions in Python 3