Python 3 compat.
Correction of error message: 'DeviceError' object has no attribute 'message'
Refartoring for python 3
Refartoring for python 3
Refartoring for python 3