Fix several python3 incompatibilities

Change-Id: Ibf5dd6c0b6bcd161364daf35d618641f6079acf5