[英]UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: invalid start byte
I'm trying to decode the string but getting an error, and here is part of the code: 我正在尝试解码字符串,但出现错误,这是代码的一部分:
#!/usr/bin/env python
import rsa
def constLenBin(s):
binary = "0"*(8-(len(bin(s))-2))+bin(s).replace('0b','')
return binary
data = 'apple'
(pubkey, privkey) = rsa.newkeys(1024)
crypto = rsa.encrypt(data.encode(), pubkey)
crypto = crypto.decode()
binary = ''.join(map(constLenBin,bytearray(crypto, 'utf-8')))
Traceback (most recent call last): 追溯(最近一次通话):
File "stdin", line 1, in module 文件“ stdin”,第1行,在模块中
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0x99:
invalid start byte 无效的起始字节
As Remco notes, \\x99
is not valid UTF8 byte. 如Remco所述, \\x99
无效的UTF8字节。 You need to specify encoding name, for example: 您需要指定编码名称,例如:
a = b'\x99'; a = a.decode('latin-1'); print(a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.