py3: decode only when necessary

In Python 2 strings are normally byte strings.
In Python 3 strings are unicode strings by default.

So msg.decode() is not necessary and can't be done in Python 3 since the
string is already a unicode string.
This adds a decode that does nothing when the input is not a byte
string.

Note that encoding can be done the same, but is not necessary here.