[英]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.