Handle bytes correctly with Python 3