Skip to content

Commit 16aac12

Browse files
committed
[serial-console] Fix garbled console output by decoding binary websocket frames
The serial-console extension's on_message callback assumed websocket frames were always str. Newer versions of websocket-client (>= 1.0) return bytes for binary frames, which the extension passed straight into print() and got rendered as a Python bytes repr (b'...\r\n \x1b[0;32m...'). This makes the serial console unusable on recent Python/websocket-client combinations (reproduced on Python 3.13 with the vendored websocket-client 1.3.1). Decode bytes to str inside on_message so that ANSI escapes and CR/LF are interpreted by the user's terminal as intended. Bumps version to 1.0.0b4 and adds a HISTORY.rst entry. Fixes #9796 Made-with: Cursor
1 parent ff6e40b commit 16aac12

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/serial-console/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Release History
22
===============
3+
1.0.0b4
4+
++++++
5+
* Fixed garbled console output where binary websocket frames were printed as a Python bytes repr (``b'...\\r\\n\\x1b[...]'``) instead of decoded text. Decode bytes to str in ``on_message`` so ANSI escapes and CR/LF are interpreted by the user's terminal.
6+
37
1.0.0b3
48
++++++
59
* Fixed an issue where admin commands were not being sent when the VM was using a custom boot diagnostics storage account.

src/serial-console/azext_serialconsole/custom.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ def on_open(_):
432432
GV.websocket_instance.send(self.access_token)
433433

434434
def on_message(_, message):
435+
# Binary websocket frames arrive as bytes from websocket-client >= 1.0.
436+
# Decode to str so that ANSI escapes and CR/LF are interpreted by the
437+
# user's terminal instead of being printed as a bytes repr (b'...').
438+
if isinstance(message, (bytes, bytearray)):
439+
message = bytes(message).decode("utf-8", errors="replace")
435440
if GV.first_message:
436441
GV.websocket_instance.send(self.access_token)
437442
GV.first_message = False

src/serial-console/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# TODO: Confirm this is the right version number you want and it matches your
1818
# HISTORY.rst entry.
19-
VERSION = '1.0.0b3'
19+
VERSION = '1.0.0b4'
2020

2121
# The full list of classifiers is available at
2222
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)