Skip to content

az serial-console connect prints raw Python bytes #33164

@praveen-pk

Description

@praveen-pk

Describe the bug

Description

az serial-console connect prints raw Python bytes repr strings (e.g. b'\r\r\n', b'login: ') instead of decoded text when running in WSL or any environment where websocket-client delivers binary WebSocket frames.

Steps to Reproduce

  1. Run az serial-console connect --name <vm> --resource-group <rg> from WSL
  2. Observe garbled output like:
b'\r\r\n'b'myvmname login: 'b'\r\r\n'b'myvmname login: '

Root Cause

In custom.py, the on_message callback passes message directly to PC.print(). When websocket-client receives a binary WebSocket frame, it delivers a bytes object. PC.print() calls Python's print() on it, which renders as b'...' repr instead of actual text.

def on_message(_, message):
    ...
    else:
        PC.print(message)  # message may be bytes, not str

Fix

Decode bytes to str before printing:

def on_message(_, message):
    ...
    else:
        if isinstance(message, bytes):
            message = message.decode('utf-8', errors='replace')
        PC.print(message)

Environment

  • OS: WSL2 (Fedora)
  • az serial-console extension version: 1.0.0b3
  • websocket-client version: 1.3.1

Related command

az serial-console connect --name --resource-group

Errors

Output looks like:

Started \x1b[0;1;39mazsecmond.service\x1b[0m - Azure security monitoring daemon.\r\n[\x1b[0;1;31mFAILED\x1b[0m] Failed to start \x1b[0;1;39mazsecmond.service\x1b[0m - Azure security monitoring daemon.\r\nSee 'systemctl status azsecmond.service' for details.\r\n

Issue script & Debug output

n/a

Expected behavior

Properly formatted output like:

[ OK ] Stopped systemd-tmpfiles-setup-dev…ic Device Nodes in /dev gracefully.
[ OK ] Stopped kmod-static-nodes.service …Create List of Static Device Nodes.
[ OK ] Stopped systemd-vconsole-setup.service - Virtual Console Setup.
[ OK ] Finished initrd-udevadm-cleanup-db.service - Cleanup udev Database.
[ OK ] Reached target initrd-switch-root.target - Switch Root.

Environment Summary

$ az --version
azure-cli 2.84.0 *

core 2.84.0 *
telemetry 1.1.0

Extensions:
azure-devops 1.0.2
serial-console 1.0.0b3

Dependencies:
msal 1.35.0b1
azure-mgmt-resource 24.0.0

Python location '/usr/sbin/python3.12'
Config directory '/var/azure'
Extensions directory '/var/azure/cliextensions'

Python (Linux) 3.12.12 (main, Jan 16 2026, 00:00:00) [GCC 15.2.1 20251211 (Red Hat 15.2.1-5)]

Legal docs and information: aka.ms/AzureCliLegal

You have 2 update(s) available. Consider updating your CLI installation with 'az upgrade'

Additional context

No response

Metadata

Metadata

Assignees

Labels

Auto-AssignAuto assign by botAuto-ResolveAuto resolve by botOutputService AttentionThis issue is responsible by Azure service team.Upgradeaz upgradeact-platform-engineering-squadcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions