Skip to content

Commit 3fb2c82

Browse files
author
Alan Christie
committed
chore: Fix eval()
1 parent 82495d3 commit 3fb2c82

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app/app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,12 @@ async def on_message_for_websocket(
448448
shutdown = True
449449
elif msg:
450450
_LOGGER.info("PREPARING %s", message_context.offset)
451-
# We know the AMQPMessage (as a string will start "b'" and end "'"
452-
# message_string = msg.decode("utf-8")
453-
message_string = eval(msg).decode("utf-8") # pylint: disable=eval-used
451+
# The msg (an AMQPMessage) cannot be decoded directly.
452+
# Instead, if we want to manipulate it (as a string)
453+
# we must str() it and eval() it! It's the easiest way because this way
454+
# it becomes a string representation of a bytestring, not a bytestring.
455+
# Once we eval() it it becomes a bytestring and we can decode it.
456+
message_string = eval(str(msg)).decode("utf-8") # pylint: disable=eval-used
454457
_LOGGER.info("TRIMMED %s", message_context.offset)
455458
if message_string[0] == "{":
456459
_LOGGER.info("IS JSON %s", message_context.offset)

0 commit comments

Comments
 (0)