423,846 Members | 2,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,846 IT Pros & Developers. It's quick & easy.

TypeError : unsupported operand type(s) for <<: 'bytes' and 'int'

P: 1
def __stringToByte(self, string):

return struct.unpack('@B', string)[0]

def __readPacket(self):

receivedPacketData = []
i = 0

while ( True ):

receivedFragment = self.__serial.read()
if ( len(receivedFragment) != 0 ):
receivedFragment = self.__stringToByte(receivedFragment)


receivedPacketData.insert(i, receivedFragment)
i += 1

if ( i >= 12 ):
if ( receivedPacketData[0] != self.__rightShift(FINGERPRINT_STARTCODE, 8) or receivedPacketData[1] != self.__rightShift(FINGERPRINT_STARTCODE, 0) ):
raise Exception('The received packet do not begin with a valid header!')
packetPayloadLength = self.__leftShift(receivedPacketData[7], 8)
packetPayloadLength = packetPayloadLength | self.__leftShift(receivedPacketData[8], 0)
1 Week Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.