Encode to bytes in Python 3