Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSConnection does not handle binary messages #417

Open
christopherjameshoward opened this issue Apr 20, 2023 · 2 comments
Open

WSConnection does not handle binary messages #417

christopherjameshoward opened this issue Apr 20, 2023 · 2 comments

Comments

@christopherjameshoward
Copy link
Contributor

Using stomp.py-8.1.0

The server I am connecting to is RabbitMQ with the rabbitmq_web_stomp plugin.

The web stomp plugin is configured to send binary messages, as documented here: https://www.rabbitmq.com/web-stomp.html#content-encoding:

web_stomp.ws_frame = binary

When I attempt to open a connection to RabbitMQ using the stomp.WSConnection class, I receive an exception:

Traceback (most recent call last):
  File "c:\git\dai\venv\lib\site-packages\stomp\transport.py", line 376, in __read
    c = self.receive()
  File "c:\git\dai\venv\lib\site-packages\stomp\adapter\ws.py", line 252, in receive
    return self.socket.recv().encode()
AttributeError: 'bytes' object has no attribute 'encode'

which leads to a ConnectFailedException:

File "c:\git\dai\venv\lib\site-packages\stomp\connect.py", line 199, in connect
    Protocol12.connect(self, *args, **kwargs)
  File "c:\git\dai\venv\lib\site-packages\stomp\protocol.py", line 529, in connect
    self.transport.wait_for_connection()
  File "c:\git\dai\venv\lib\site-packages\stomp\transport.py", line 318, in wait_for_connection
    raise exception.ConnectFailedException()
stomp.exception.ConnectFailedException

The problem seems to be that the WSTransport.receive method assumes that all websocket messages are strings, and tries to convert them back into bytes: https://github.com/jasonrbriggs/stomp.py/blob/dev/stomp/adapter/ws.py#L215

I think it would be possible to fix this issue by calling the recv_data method, rather than recv:

opcode, data = self.socket.recv_data()
return data

If you agree, I would be happy to submit a PR.

@mfmarche
Copy link
Contributor

hi, that seems like a reasonable solution. There would need to be a configuration at the WSConnection constructor, default as tring, since by default RabbitMQ is configured as UTF-8

By default, the Web STOMP plugin will expect to handle messages encoded as UTF-8

@christopherjameshoward
Copy link
Contributor Author

Here is the PR: #419

jasonrbriggs added a commit that referenced this issue Jun 29, 2023
…bsocket-messages

[#417] Add support for sending/receiving binary websocket messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants