I'm a beginner at Python and am running this piece of code:
myInteger = 0
multiple = 256
myString = ""
for i in pkt:
myString += "%02x" %struct.unpack("B", i)[0]
myInteger += struct.unpack("B", i)[0] * multiple
multiple = 1
where pkt is a byte string.
This code works fine in Python 2, but after upgrading to 3 it gives an error:
TypeError: 'int' does not support the buffer interace
After some research, I found out that in Python2, a string of bytes is a string and so, when iterating over it we get single byte strings. But in Python3, we get integers and apparently, struct.unpack does not accept integers.
I read the answer for these questions, but I can't understand how to change the code in order to get it running.
Why do I get an int when I index bytes?
iterate over individual bytes in python3
Porting struct.unpack from python 2.7 to 3
How can I iterate over pkt and get a valid value to pass to struct.unpack?
I apologize if this is an obvious question but I really can't seem to get this working. Thanks in advance!
EDIT
So maybe to be more specific, I am trying to do a ble scan using raspberry pi and I am using the code provided by:
https://github.com/switchdoclabs/BeaconAirPython/blob/master/ble/blescan.py
The code runs on Python2, but on Python3 gives the error mentioned above on every call on struct.pack.
====