1
2
3
4
5
6
7
8
def test():
import chardet
data = b"\xe4\xb8\xad\xe6\x96\x87"
if isinstance(data, bytes):
encoding = chardet.detect(data)["encoding"]
print("encoding", encoding)
text = data.decode(encoding, "ignore")
print("text", text)