diff --git a/gmqtt/__init__.py b/gmqtt/__init__.py index 93dc429..3679b0f 100644 --- a/gmqtt/__init__.py +++ b/gmqtt/__init__.py @@ -13,7 +13,7 @@ "Mikhail Turchunovich", "Elena Nikolaichik" ] -__version__ = "0.6.7" +__version__ = "0.6.8" __all__ = [ diff --git a/gmqtt/client.py b/gmqtt/client.py index afa35d5..860afc0 100644 --- a/gmqtt/client.py +++ b/gmqtt/client.py @@ -17,7 +17,7 @@ class Message: def __init__(self, topic, payload, qos=0, retain=False, **kwargs): - self.topic = topic + self.topic = topic.encode('utf-8', errors='replace') if isinstance(topic, str) else str self.qos = qos self.retain = retain self.dup = False diff --git a/gmqtt/mqtt/package.py b/gmqtt/mqtt/package.py index 4f2c62a..5b87b8b 100644 --- a/gmqtt/mqtt/package.py +++ b/gmqtt/mqtt/package.py @@ -150,8 +150,12 @@ def build_package(cls, subscriptions, protocol, **kwargs) -> Tuple[int, bytes]: subscription_identifier = kwargs.get('subscription_identifier', cls.sentinel) for s in subscriptions: - remaining_length += 2 + len(s.topic) + 1 - topics.append(s.topic) + topic = s.topic + if isinstance(topic, str): + topic = topic.encode() + + remaining_length += 2 + len(topic) + 1 + topics.append(topic) # if subscription_identifier hasn't been passed in kwargs, # we will use the first identifier for all subscriptions;