Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

struct.unpack causing TypeError:'int' does not support the buffer interface

I am using the struct module in Python 3.4 like so:

length = struct.unpack('>B', data[34])[0]

data looks like this:

b'\x03\x01\x0e}GZ\xa8\x8e!\x1c\x7ft\xe8\xf9G\xbf\xb1\xdf\xbek\x8d\xb3\x05e~]N\x97\xad\xcaz\x03tP\x00\x00\x1eV\x00\xc0\n\xc0\t\xc0\x13\xc0\x14\xc0\x07\xc0\x11\x003\x002\x009\x00/\x005\x00\n\x00\x05\x00\x04\x01\x00\x00f\x00\x00\x00\x1b\x00\x19\x00\x00\x16parteek.khalsabani.com\xff\x01\x00\x01\x00\x00\n\x00\x08\x00\x06\x00\x17\x00\x18\x00\x19\x00\x0b\x00\x02\x01\x00\x00#\x00\x003t\x00\x00\x00\x10\x00\x1b\x00\x19\x08spdy/3.1\x06spdy/3\x08http/1.1\x00\x05\x00\x05\x01\x00\x00\x00\x00'

I am getting

TypeError: 'int' does not support the buffer interface.

I am new at using struct. What's wrong?

like image 790
Darksilence Avatar asked Feb 11 '23 00:02

Darksilence


1 Answers

That's because you're passing it the contents of data[34] which is an int.

Try using data[34:35] instead, which is a one element byte array.

like image 103
martineau Avatar answered Feb 16 '23 02:02

martineau