fixing exceptions for Python 3 compatibility