add python3 compatibility changing exception handling

add python3 compatibility as you suggested in #6