将字节对象转换为utf-8

问题描述 投票:0回答:1
k = b'\xf2-\x92\xe7\x98\x90@\xddF\xbf\x13I4\x92\x0f\xc5'

我试着用'utf-8'编码,但我得到一个错误信息

utf-8' codec can't decode byte 0xf2 in position 0: invalid continuation byte

我如何才能正确地将其转换为字符串对象?

python-3.x utf-8 byte
1个回答
-1
投票

##更新好吧,我得看看你的字节,这是错误的编码,你需要使用ISO-8859-1。

encoding = 'ISO-8859-1'
k = b'\xf2-\x92\xe7\x98\x90@\xddF\xbf\x13I4\x92\x0f\xc5'.decode(encoding)
print(type(k))

这将解决这个问题

© www.soinside.com 2019 - 2024. All rights reserved.