Python struct.unpack errors with TypeError: a bytes-like object is required, not 'str'
问题 Can someone please help with the following line of code and Error? I am unfamiliar with python value conversions. The specific line that generates the error is: value = struct.unpack("<h",chr(b)+chr(a))[0] TypeError: a bytes-like object is required, not 'str' The code fragment is: if packet_code ==0x80: # raw value row_length = yield a = yield b = yield value = struct.unpack("<h",chr(b)+chr(a))[0] The input data is: b'\x04\x80\x02\x00\xb2\xcb\xaa\xaa\x04\x80\x02\x00p\r\xaa\xaa\x04\x80\x02\x00