Plugwise-2-py icon indicating copy to clipboard operation
Plugwise-2-py copied to clipboard

TypeError crash in debug print

Open tvwerkhoven opened this issue 3 years ago • 0 comments

I get an occasional TypeError crash running on python3.8 as follows, any ideas how to solve?

Traceback (most recent call last):
  File "./Plugwise-2.py", line 1471, in <module>
    main=PWControl()
  File "./Plugwise-2.py", line 175, in __init__
    self.set_interval_production(self.circles[-1])
  File "./Plugwise-2.py", line 296, in set_interval_production
    c.set_log_interval(c.loginterval, c.production)
  File "/home/pi/plugwise-2-py/plugwise/api.py", line 865, in set_log_interval
    return self._expect_response(PlugwiseAckMacResponse, seqnr)
  File "/home/pi/plugwise-2-py/plugwise/api.py", line 511, in _expect_response
    resp = self._comchan.expect_response(response_class, self._mac(), seqnr, retry_timeout)
  File "/home/pi/plugwise-2-py/plugwise/api.py", line 189, in expect_response
    resp.unserialize(msg)
  File "/home/pi/plugwise-2-py/plugwise/protocol.py", line 402, in unserialize
    PlugwiseAckResponse.unserialize(self, response)
  File "/home/pi/plugwise-2-py/plugwise/protocol.py", line 380, in unserialize
    PlugwiseResponse.unserialize(self, response)
  File "/home/pi/plugwise-2-py/plugwise/protocol.py", line 307, in unserialize
    debug("STRU      "+header+" "+logf(self.function_code)+" "+logf(self.command_counter)+" <data> "+logf(crc)+" "+footer)
TypeError: can only concatenate str (not "bytes") to str

all variables are output from struct.unpack(), so it seems it's fed data it doesn't comprehend. The code leading to this crash is:

        header, self.function_code, self.command_counter = struct.unpack("4s4s4s", response[:12])
        crc, footer = struct.unpack("4s2s", response[-6:])
        raw_msg_len = len(response)


        #check for protocol errors
        protocol_error = ''
        if footer != self.PACKET_FOOTER:
            protocol_error = "broken footer!"
        else:
            footer = '<---'
        if header != self.PACKET_HEADER:
            protocol_error = "broken header!"
        else:
            if header5:
                header = '-->>'
            else:
                header = '--->'
        if crc != self.calculate_checksum(response[4:-6]):
            protocol_error = "checksum error!"
        debug("STRU      "+header+" "+logf(self.function_code)+" "+logf(self.command_counter)+" <data> "+logf(crc)+" "+footer)

tvwerkhoven avatar Sep 20 '21 18:09 tvwerkhoven