How to convert bytes to a string in Python 3
Decode the bytes with the right encoding:
b = b"hello"
s = b.decode("utf-8")
# or
s = str(b, "utf-8")If the data may contain bad bytes:
b.decode("utf-8", errors="replace")Do not use str(b) alone. It returns the text b'hello' instead of decoding. To go the other way use s.encode("utf-8").