change except with as to support python3
change os.chmod 0777 to 0o777