Skip to content

Commit

Permalink
Possible fix to message encoding issue (#1990)
Browse files Browse the repository at this point in the history
It throws an exception when trying to parse to JSON. Could use a second opinion on this solution. Original Codelab instructions available [here](https://codelabs.developers.google.com/codelabs/cloud-iot-core-overview/index.html?index=..%2F..index#0).
  • Loading branch information
CarlosMendonca authored and gguuss committed Feb 1, 2019
1 parent c630c60 commit 1cad11a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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 = message.payload
payload = message.payload.decode('utf-8')
print('Received message \'{}\' on topic \'{}\' with Qos {}'.format(
payload, message.topic, str(message.qos)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def callback(message):
subscribed topic.
"""
try:
data = json.loads(message.data)
data = json.loads(message.data.decode('utf-8'))
except ValueError as e:
print('Loading Payload ({}) threw an Exception: {}.'.format(
message.data, e))
Expand Down

0 comments on commit 1cad11a

Please sign in to comment.