GeezerVison is showing github.com — CLI `_echo` doesn't work without `import rich` for non-String reports · Issue #1618 · python-kasa/python-kasa
CLI _echo doesn't work without import rich for non-String reports #1618DescriptionFor example this CLI command will throw an exception is rich isn't installed, although it works fine otherwise:
kasa --host 192.168.1.168 --username xxx --password xxx feature check_latest_firmware
Discovering device 192.168.1.168 for 10 seconds
Executing action check_latest_firmware
Raised error: expected string or bytes-like object, got 'UpdateInfo'
Run with --debug enabled to see stacktrace
the reason for this error reported by --debug:
[...]
Raised error: expected string or bytes-like object, got 'UpdateInfo'
Traceback (most recent call last):
[...]
File "/home/mash/.local/share/uv/tools/python-kasa/lib/python3.13/site-packages/kasa/cli/feature.py", line 125, in feature
echo(response)
~~~~^^^^^^^^^^
File "/home/mash/.local/share/uv/tools/python-kasa/lib/python3.13/site-packages/kasa/cli/common.py", line 57, in echo
_echo(*args, **kwargs)
~~~~~^^^^^^^^^^^^^^^^^
File "/home/mash/.local/share/uv/tools/python-kasa/lib/python3.13/site-packages/kasa/cli/common.py", line 45, in wrapper
message = rich_formatting.sub("", message)
TypeError: expected string or bytes-like object, got 'UpdateInfo'
The regex substitution used in this replacement for richs print() function only works for strings.
More complex objects need to be preprocessed by repr() in advance. Activityadded a commit that references this issue on Nov 29, 2025This issue will close once commit a4cd0b8 is merged into the 'master' branch.a4cd0b8 rytilahti commented on Nov 30, 2025 This seems to work for me, with & without rich (14.2.0) using python 3.12:
Which versions are you using? mash-graz commented on Nov 30, 2025
This seems to work for me, with & without rich (14.2.0) using python 3.12.
Could you please execute this little script (test.py), which should demonstrate the actual cause of this issue:
import re
class TestObj:
member_num = 12
member_str = "xxx"
to = TestObj()
re.sub(r'[x]', '', to)
The output will look very similar to this:
 github-actions commented on Mar 1, 2026 There hasn't been any activity on this issue recently. This issue has been automatically marked as stale because of that. It will be closed if no further activity occurs.
Please make sure to update to the latest python-kasa version and check if that solves the issue.
Thank you for your contributions.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|