需要一个类似字节的对象,而不是python中的“ str”错误

猎人

我在写代码

image = Image.open(filename)    #opening the image
binary = bin(int(binascii.hexlify(message), 16))    #converting string into binary
binary = binary.append('1111111111111110')   #adding delimeter at the end 
binary = binary**.lstrip('0b')   #removing the starting ob of binary

............继续

由于第二行,我收到此错误

** binary = bin(int(binascii.hexlify(message),16))

TypeError:需要一个类似字节的对象,而不是'str'

我不明白这个错误,似乎没有任何工作

莱昂内尔·福克斯克罗夫特

该变量message包含一个字符串,但是它必须是字节序列。要将字符串编码为字节,可以执行以下操作:

message.encode('utf-8')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:需要一个类似字节的对象,而不是'str'

使用Python 3.5,抛出错误:TypeError:需要一个类似字节的对象,而不是'str'

Python错误:TypeError:需要一个类似字节的对象,而不是'str'

TypeError:需要一个类似字节的对象,而在python和CSV中不是'str'

TypeError:需要一个类似字节的对象,而在python和CSV中不是'str'

类型错误:需要一个类似字节的对象,不是“str”,但类型显示字节

需要一个类似字节的对象,而不是'str'

类型错误:需要一个类似字节的对象,而不是 'str' WSGI 服务器

如何解决Json错误:TypeError:需要一个类似字节的对象,而不是'str'

ANSIBLE:boto-“类型错误:需要一个类似字节的对象,而不是‘str’”

诱变剂:类型错误:需要一个类似字节的对象,而不是“str”

类型错误:需要一个类似字节的对象,而不是使用 BytesIO 的“str”

TypeError:需要一个类似字节的对象,而在Python 3中打开Python 2 Pickle文件时不是'str'

类型错误:需要一个类似字节的对象,而不是无服务器和 Python3 的“str”

TypeError:在Python3中写入文件时需要一个类似字节的对象,而不是'str'

Python 3.6:TypeError:在尝试打印页面中的所有链接时,需要一个类似字节的对象,而不是'str'

TypeError:在Python 3.5.1中使用REST时需要一个类似字节的对象,而不是'str'

Python 3-TypeError:需要一个类似字节的对象,而不是'str'

Python 2到3“ TypeError:需要一个类似字节的对象,而不是'str'”

TypeError:需要一个类似字节的对象,而不是'str'–用Python保存JSON数据

Python3写入gzip文件-memoryview:需要一个类似字节的对象,而不是'str'

Python 3.7 TypeError:需要一个类似字节的对象,而不是'str'

Python 3 升级,需要一个类似字节的对象,而不是“str”

python 3.5:“ TypeError:memoryview:需要一个类似字节的对象,而不是'str'”

Python3 TypeError:需要一个类似字节的对象,而不是“str”

Python3 .replace产生TypeError:需要一个类似字节的对象,而不是'str'

Python 3,TypeError:需要一个类似字节的对象,而不是'str'

TypeError:需要一个类似字节的对象,而不是从文件中读取时的“ str”

TypeError:需要一个类似字节的对象,而不是subprocess.check_output中的“ str”