2015-02-05 13 views
5

Sto usando il modulo struct in Python 3.4 in questo modo:struct.unpack causando TypeError: 'int' non supporta l'interfaccia buffer di

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

data assomiglia a questo:

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 sto diventando

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

Sono nuovo nell'utilizzo di struct. Cosa c'è che non va?

risposta

8

Questo perché si sta passando il contenuto del data[34] che è un int.

Provare a utilizzare data[34:35] invece, che è un array di byte a un elemento.

Problemi correlati