Python 3 fixes for chmod and exceptions