wialon / gmqtt

Python MQTT v5.0 async client
MIT License
385 stars 53 forks source link

server keep live bug #117

Open fangaofeng opened 3 years ago

fangaofeng commented 3 years ago

when there is keeplive in connack, the exception: result = self._handle_packet(cmd, packet) File "E:\workspace\mqtt-simulator\env\lib\site-packages\gmqtt\mqtt\handler.py", line 214, in _handle_packet handler(cmd, packet) File "E:\workspace\mqtt-simulator\env\lib\site-packages\gmqtt\mqtt\handler.py", line 286, in _handle_connack_packet File "E:\workspace\mqtt-simulator\env\lib\site-packages\gmqtt\mqtt\handler.py", line 257, in _update_keepalive_if_needed self._connection.keepalive = self._keepalive File "E:\workspace\mqtt-simulator\env\lib\site-packages\gmqtt\mqtt\connection.py", line 109, in keepalive self._keep_connection_callback = asyncio.get_event_loop().call_later(self._keepalive / 2, self._keep_connection) TypeError: unsupported operand type(s) for /: 'list' and 'int'

    def _parse_properties(self, packet):
        if self.protocol_version < MQTTv50:
            # If protocol is version is less than 5.0, there is no properties in packet
            return {}, packet
        properties_len, left_packet = unpack_variable_byte_integer(packet)
        packet = left_packet[:properties_len]
        left_packet = left_packet[properties_len:]
        properties_dict = defaultdict(list)
        while packet:
            property_identifier, = struct.unpack("!B", packet[:1])
            property_obj = Property.factory(id_=property_identifier)
            if property_obj is None:
                logger.critical('[PROPERTIES] received invalid property id {}, disconnecting'.format(property_identifier))
                return None, None
            result, packet = property_obj.loads(packet[1:])
            for k, v in result.items():
                properties_dict[k].append(v)   # this is list ,but need int
        properties_dict = dict(properties_dict)
        return properties_dict, left_packet
Mixser commented 3 years ago

Hi @fangaofeng, please tell us more about your setup: 1) Python Version 2) Which broker do you use (and its version too)

nicoCalvo commented 2 years ago

+1 I'm facing the same issue. Broker mosquitto 2.x - python 3.8 or 3.9 both failing, It seems that on version 2 the server keepalive is sent and for previous versions it wasn't. I can only reproduce it with mosquitto 2.x