[update] more exception handling compatible with Python 3
[update] using six library to port the lib to python 3.