Roonapi Python Library - websocket-client Compatibility Issue

I’m experiencing a websocket incompatibility issue with the roonapi Python library when using recent versions of websocket-client.

Environment:

  • Python 3.14
  • roonapi (latest from PyPI)
  • websocket-client 1.9.0

Error:

ERROR roonapisocket – Error while parsing message ‘<websocket._app.WebSocketApp object at 0x…>’

AttributeError: ‘WebSocketApp’ object has no attribute ‘decode’

Issue: The error occurs in roonapisocket.py line 127, where the code attempts to call .decode(“utf-8”) on what appears to be a WebSocketApp object rather than a bytes object. This suggests the websocket-client library API has changed between versions.

Workaround: Downgrading to websocket-client==1.6.4 resolves the issue, but this creates conflicts with other packages (like Jupyter) that require websocket-client >= 1.7.

Question: Are there plans to update roonapi to support newer versions of websocket-client? Or is there a recommended approach for managing this dependency conflict?

1 Like

I’ll add this to my to do list.

Feel free to add a GitHub issue if that’s easy.

Given you have a reproducible case if yiu can easily find out at which point the library broke that would be helpful.

@Michael_DePhillips I had a quick look - updated the library to websocket-client to 1.9.0 and tried to run my examples.

They all seemed to run fine.

I’ve started to look at releasing a new version - but since I haven’t touched the library or the build environment for a quite a while - will take a little work to get the build and dependencies to work correctly..

But please do more digging in the meantime.

1 Like

Hi
I had the same issue and pinned websocket-client to 1.6.4 in my project.

You’re right about the cause: the callback signature changed in recent websocket-client versions. The on_message callback receives the WebSocketApp object as first argument instead of just the message data. The roonapi library would need to update its callback functions to handle this, but until that happens…
The cleanest solution is to use a dedicated virtual environment for your roon stuff. That way the pinned version doesn’t conflict with Jupyter or anything else.

For my setup I went with this since the NFC controller runs in its own venv anyway. Works without any issues.

As far as I can see the code should cope with what you describe. This defensive coding was from way before my time:-

    def on_message(self, w_socket, message=None):
        """Handle message callback."""
        if not message:
            message = w_socket  # compatability fix because of change in websocket-client v0.49
        try:
            message = message.decode("utf-8")
            lines = message.split("\n")
            header = lines[0]
            body = ""

I have a dev version of the library running against websocket_client 1.9.0 and it runs my demo subscription code fine.

PR here if anyone is interested: Update websocket client library version by pavoni · Pull Request #85 · pavoni/pyroon · GitHub

1 Like