Encode strings so they can be serialized to bytes in Python 3.x.