Skip to content

fix message.payload str casting. #1313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def on_subscribe(self, unused_client, unused_userdata, unused_mid,

def on_message(self, unused_client, unused_userdata, message):
"""Callback when the device receives a message on a subscription."""
payload = str(message.payload)
payload = message.payload
print('Received message \'{}\' on topic \'{}\' with Qos {}'.format(
payload, message.topic, str(message.qos)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you remove the str(message.qos) from this line too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A string formatter will automatically cast it into string. So, it could be an useless casting, but really doesn't matter. (message.qos is an int type, I guess)

The perfect printing might be like

print('Received message \'{}\' on topic \'{}\' with Qos {}'.format(
             payload.decode(), message.topic, message.qos))

But exposing type of payload could be useful to specify that it is a byte type.

Therefore, it just depends on the author's intention, just for logging or providing extra information though the log.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave as-is.


Expand Down