UnicodeDecodeError:“utf8”编解码器无法解码位置0中的字节0x99:起始于无效

2024-10-01 07:35:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图解码字符串,但得到一个错误,下面是部分代码:

#!/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
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0:
invalid start byte


Tags: 字符串代码indatabin错误byte解码