8000 Possible fix to message encoding issue (#1990) · devlance/python-docs-samples@1cad11a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1cad11a

Browse files
CarlosMendoncagguuss
authored andcommitted
Possible fix to message encoding issue (GoogleCloudPlatform#1990)
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).
1 parent c630c60 commit 1cad11a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

iot/api-client/end_to_end_example/cloudiot_pubsub_example_mqtt_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def on_subscribe(self, unused_client, unused_userdata, unused_mid,
122122

123123
def on_message(self, unused_client, unused_userdata, message):
124124
"""Callback when the device receives a message on a subscription."""
125-
payload = message.payload
125+
payload = message.payload.decode('utf-8')
126126
print('Received message \'{}\' on topic \'{}\' with Qos {}'.format(
127127
payload, message.topic, str(message.qos)))
128128

iot/api-client/end_to_end_example/cloudiot_pubsub_example_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def callback(message):
152152
subscribed topic.
153153
"""
154154
try:
155-
data = json.loads(message.data)
155+
data = json.loads(message.data.decode('utf-8'))
156156
except ValueError as e:
157157
print('Loading Payload ({}) threw an Exception: {}.'.format(
158158
message.data, e))

0 commit comments

Comments
 (0)
0