Compatibility with python 3

Replace deprecated methods with ones supported on python 2 and 3