Environment is Python 3
Questions:
Using the Binascii method has been error typeerror:a Bytes-like object is required, not ' str '
# Coding:utf-8 Import 'worker'=print(b)#b = Binascii.b2a_hex (a)#typeerror:a Bytes-like object is required, not ' str '
Workaround:
Later changes to the following code will not be error
b = Binascii.b2a_hex (A.encode ())
Principle:
In the new version of Python3, the Unicode type is removed, instead it is a string type (str) that uses Unicode characters, the string type (str) becomes the underlying type as shown below, and the encoding becomes the byte type (bytes) but the two functions are used the same way:
Decode encode
bytes------> str (Unicode)------>bytes
' English ' # Specifies the string type Object ustr = u.encode ('gb2312'# encoded with gb2312 encoding for u, Get bytes type Object stru1 = Str.decode ('gb2312')# Decodes the string str with GB2312 encoding to get the string type Object u1u2 = Str.decode ('utf-8')# If you decode str with UTF-8 encoding, you will not be able to restore the original string contents
Python 3 Error resolution using the Binascii method