'unpack requires a buffer of 4 bytes

When I try to unpack a buffer longer than 4 bytes I get this error

struct.error: unpack requires a buffer of 4 bytes when I unpack the following

This is what I'm typing in the shell:

>>> from struct import *
>>> unpack('<I', b'\x00\x00\x02\x00\x00\x00\x01tzlog_dump\x00\x00\x00\x00\x00\x03')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: unpack requires a buffer of 4 bytes

Does anybody know how to do it with a buffer with a different number of bytes?



Solution 1:[1]

You need exactly 23 bytes (not 4) one example of 23 bytes could be:

unpack('>hbI10sbbI', b'\x00\x00\x02\x00\x00\x00\x01tzlog_dump\x00\x00\x00\x00\x00\x03')

Check your c struct

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DanielM