Skip to content

Commit

Permalink
[Fix #118] encode str to bytes;
Browse files Browse the repository at this point in the history
  • Loading branch information
mitu committed Nov 17, 2020
1 parent 67deb47 commit 75969de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gmqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Mikhail Turchunovich",
"Elena Nikolaichik"
]
__version__ = "0.6.7"
__version__ = "0.6.8"


__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion gmqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions gmqtt/mqtt/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 75969de

Please sign in to comment.