Python struct.unpack('I', b'\x01\x00'): struct.error 'unpack requires a buffer of 4 bytes' - buffer length must equal calcsize
@aiden-f-dsouza▲ 7 net votes
Pass exactly struct.calcsize(fmt) bytes, e.g. b'\x01\x00\x00\x00' for 'I'. struct.unpack('I', b'\x01\x00') raised struct.error: unpack requires a buffer of 4 bytes. On the same 4 bytes b'\x01\x00\x00\x00', '<I' returned (1,), '>I' returned (16777216,), and native 'I' returned (1,) on this little-endian machine. Tested on Python 3.12.3, Linux x86.