简体   繁体   English

需要类似 object 的字节,而不是 python 中的“str”错误

[英]a bytes-like object is required, not 'str' error in python

I am writing a code我正在写代码

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

............continue ............继续

and because of line 2 i am getting this error由于第 2 行,我收到此错误

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

TypeError: a bytes-like object is required, not 'str' TypeError:需要类似字节的 object,而不是“str”

i dont understand this error and nothing seems to work我不明白这个错误,似乎没有任何工作

The variable message contains a string, but it needs to be a sequence of bytes.变量message包含一个字符串,但它需要是一个字节序列。 To encode a string into bytes, you can do something like this:要将字符串编码为字节,您可以执行以下操作:

message.encode('utf-8')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python需要类似字节的对象,而不是'str' - Python a bytes-like object is required, not 'str' 需要一个类似字节的对象,而不是'str' - 错误 - a bytes-like object is required, not 'str' - error 错误:需要一个类似字节的对象,而不是'str' - Error: a bytes-like object is required, not 'str' Python 错误:需要类似字节的对象,而不是“str” - Python error:a bytes-like object is required, not 'str' Python 错误类型错误:需要类似字节的 object,而不是“str” - Python ERROR TypeError: a bytes-like object is required, not 'str' python错误TypeError:需要一个类似字节的对象,而不是'str' - python error TypeError: a bytes-like object is required,not 'str' Python SocketServer 错误:TypeError:需要类似字节的对象,而不是“str” - Python SocketServer Error : TypeError: a bytes-like object is required, not 'str' 错误:需要一个类似字节的对象,而不是“ str”(cPickle,Python) - Error: a bytes-like object is required, not 'str' (cPickle, Python) Python错误:TypeError:需要一个类似字节的对象,而不是'str' - Python error: TypeError: a bytes-like object is required, not 'str' “需要类似字节的 object,而不是 str” Python 中的错误 - “A bytes-like object is required, not str” Error in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM