rasa: Socket Channel not working in rasa 3.0.0

Rasa Open Source version

3.0.0

Rasa SDK version

3.0.0

Rasa X version

No response

Python version

3.8

What operating system are you using?

Linux

What happened?

Using the rasa chat widget to talk to the bot throws the following exception in rasa 3.0.0:

[2021-11-28 13:09:58 +0000] [4700] [ERROR] Exception occurred while handling uri: 'http://localhost:5005/socket.io/?EIO=4&transport=polling&t=Nrcgg60'
Traceback (most recent call last):
  File "handle_request", line 83, in handle_request
    class Sanic(BaseSanic, metaclass=TouchUpMeta):
  File "/opt/venv/lib/python3.8/site-packages/engineio/asyncio_server.py", line 317, in handle_request
    return await self._make_response(r, environ)
  File "/opt/venv/lib/python3.8/site-packages/engineio/asyncio_server.py", line 385, in _make_response
    response = make_response(
  File "/opt/venv/lib/python3.8/site-packages/engineio/async_drivers/sanic.py", line 102, in make_response
    return HTTPResponse(body=payload, content_type=content_type,
TypeError: 'NoneType' object is not callable

This did not happen in rasa 2.8.15.

This repo contains a reproducible example.

Command / Request

No response

Relevant log output

No response

Definition of done

  • Determine if the cause is in Rasa Open Source 3.0
  • If the problem is in Rasa Chat Widget, update this issue and move to Fabric backlog
  • Try to add test for this?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (9 by maintainers)

Most upvoted comments

python-engineio has released a new version with the fix: 4.3.1 🎉

I am facing similar error with rasa 3.0.1 I just added https://cdn.jsdelivr.net/npm/rasa-webchat/lib/index.js on my index.html

[2021-12-02 20:35:12 -0500] [88145] [ERROR] Exception occurred while handling uri: 'http://localhost:5005/socket.io/?EIO=4&transport=polling&t=NrzxbjF'
Traceback (most recent call last):
  File "handle_request", line 83, in handle_request
    class Sanic(BaseSanic, metaclass=TouchUpMeta):
  File "/Users/jona/Library/Caches/pypoetry/virtualenvs/rasa-assistant-_8IB3lkj-py3.7/lib/python3.7/site-packages/engineio/asyncio_server.py", line 317, in handle_request
    return await self._make_response(r, environ)
  File "/Users/jona/Library/Caches/pypoetry/virtualenvs/rasa-assistant-_8IB3lkj-py3.7/lib/python3.7/site-packages/engineio/asyncio_server.py", line 388, in _make_response
    response_dict['response'], environ)
  File "/Users/jona/Library/Caches/pypoetry/virtualenvs/rasa-assistant-_8IB3lkj-py3.7/lib/python3.7/site-packages/engineio/async_drivers/sanic.py", line 103, in make_response
    status=int(status.split()[0]), headers=headers_dict)
TypeError: 'NoneType' object is not callable

I tried installing @nimitkh version using poetry but I got a version error with sanic==21.6.0 and sanic-routing==0.7.0

image

I have experimented this on rasa/webchat/ and it’s working fine on rasa 3.0 [MacOS] with:

pip install sanic==21.6.0
pip install Sanic-Cors==1.0.0
pip install sanic-routing==0.7.0

@ltfschoen I have several bots working with the botfront widget and 3.x here. They’re all on various 3.x releases.

i figured out what i was doing wrong. like you say https://github.com/botfront/rasa-webchat does work fine with Rasa 3.x.

first thing i hadn’t done was in credentials.yml i had session_persistence: true/false instead of just session_persistence: true, but that wasn’t the issue.

i updated the index.html file so it had socketUrl: "http://<MY_EC2_PUBLIC_IP>:5005" when i ran the web server i still got error GET http://<MY_EC2_PUBLIC_IP>:5005/socket.io/?EIO=3&transport=polling&t=OIt2MeS 400 (Bad Request)

but when i create EC2 Security > Inbound rule to allow port forwarding on 5000 and 5005 on TCP 0.0.0.0/0 it still didn’t work, but then i noticed in the terminal window of the Rasa server where i’d run python -m rasa run --enable-api --cors "*", it had an error shown: Rasa server is up and running. The client is using an unsupported version of the Socket.IO or Engine.IO protocols (further occurrences of this error will be logged with level INFO).

so given that i knew that EIO was an abbreviation for the EngineIO version since i recently answered this stackoverflow question https://stackoverflow.com/questions/74265891/what-is-eio-3transport-pollingt-in-socket-io/74508268#74508268, i quicky checked that the Rasa server was running

python -m pip show python-engineio  -> 4.3.1
python -m pip show python-socketio  -> 5.5.0

but the error was telling me that the client was using an unsupported version, which was EngineIO v3, since the query string parameters from the client were EIO=3, so i needed it to show EIO=4 instead…

in index.html i was using <script src="https://cdn.jsdelivr.net/npm/rasa-webchat@1.5.0/lib/index.min.js" type="text/javascript"></script>, but when i changed @1.5.0 to @1.0.0 or removed the version number so it became <script src="https://cdn.jsdelivr.net/npm/rasa-webchat/lib/index.min.js" type="text/javascript"></script> it gave me an error saying WebChat.default.init is undefined, so i simply changed that code to WebChat.default instead of WebChat.default.init, since the latest version doesn’t use .init. See https://github.com/botfront/rasa-webchat/blob/master/dev/src/index.html#L8, and when i did that and restarted the Flask server and refreshed the webpage at http://<MY_EC2_PUBLIC_IP>:5000 it finally worked

@ltfschoen I have several bots working with the botfront widget and 3.x here. They’re all on various 3.x releases.

The socket issue still persists even with the latest Rasa version (3.2.4). I’m using rasa-webchat as the chat interface. The issue can be reproduced by:

  1. Closing the chat session (by closing the browser tab).
  2. Navigating to a different page and coming back to the page with the chatbot.
Screenshot 2022-07-29 at 12 09 52 PM

Version Reference:

Python packages: (Python: 3.8.4)
rasa==3.2.4
rasa-sdk==3.2.0
sanic==21.12.1
Sanic-Cors==2.0.1
sanic-jwt==1.8.0
sanic-routing==0.7.2
python-engineio==4.3.3
python-socketio==5.7.1

JavaScript dependencies: (Node: 12.16.1)
socket.io-client@4.5.1

@amn41 may have discovered a different issue with python-engineio 4.3.1 and sanic 21.9.3

I’m having an issue with sanic websockets and Rasa Web Chat and suspect it’s related to this. I’m running the latest docker image rasa/rasa:3.0.5 which has the following installed:

$ pip list | grep anic
sanic                   21.9.3
Sanic-Cors              1.0.1
sanic-jwt               1.7.0
sanic-plugin-toolkit    1.2.1
sanic-routing           0.7.2

If I hook up Rasa Web Chat to this server, I get an exception when trying to start a chat:

rasa-production_1  | 2022-01-20 10:34:08 DEBUG    rasa.core.channels.socketio  - User JRwVm-eqBQ_Hkr90AAAB connected to socketIO endpoint.
rasa-production_1  | Exception occurred while handling uri: 'ws://docker-stack/socket.io/?EIO=4&transport=websocket&sid=z75hbjVaYkWkQmbdAAAA'
rasa-production_1  | Traceback (most recent call last):
rasa-production_1  |   File "/opt/venv/lib/python3.8/site-packages/sanic/server/protocols/websocket_protocol.py", line 119, in websocket_handshake
rasa-production_1  |     subprotocols = list(subprotocols)
rasa-production_1  |   File "/usr/lib/python3.8/typing.py", line 261, in inner
rasa-production_1  |     return func(*args, **kwds)
rasa-production_1  |   File "/usr/lib/python3.8/typing.py", line 685, in __getitem__
rasa-production_1  |     params = tuple(_type_check(p, msg) for p in params)
rasa-production_1  |   File "/usr/lib/python3.8/typing.py", line 685, in <genexpr>
rasa-production_1  |     params = tuple(_type_check(p, msg) for p in params)
rasa-production_1  |   File "/usr/lib/python3.8/typing.py", line 149, in _type_check
rasa-production_1  |     raise TypeError(f"{msg} Got {arg!r:.100}.")
rasa-production_1  | TypeError: Parameters to generic types must be types. Got 0.
rasa-production_1  | 
rasa-production_1  | During handling of the above exception, another exception occurred:
rasa-production_1  | 
rasa-production_1  | Traceback (most recent call last):
rasa-production_1  |   File "handle_request", line 83, in handle_request
rasa-production_1  |     class Sanic(BaseSanic, metaclass=TouchUpMeta):
rasa-production_1  |   File "/opt/venv/lib/python3.8/site-packages/engineio/asyncio_server.py", line 271, in handle_request
rasa-production_1  |     packets = await socket.handle_get_request(environ)
rasa-production_1  |   File "/opt/venv/lib/python3.8/site-packages/engineio/asyncio_socket.py", line 89, in handle_get_request
rasa-production_1  |     return await getattr(self, '_upgrade_' + transport)(environ)
rasa-production_1  |   File "/opt/venv/lib/python3.8/site-packages/engineio/asyncio_socket.py", line 142, in _upgrade_websocket
rasa-production_1  |     return await ws(environ)
rasa-production_1  |   File "/opt/venv/lib/python3.8/site-packages/engineio/async_drivers/sanic.py", line 122, in __call__
rasa-production_1  |     self._sock = await protocol.websocket_handshake(request)
rasa-production_1  |   File "/opt/venv/lib/python3.8/site-packages/sanic/server/protocols/websocket_protocol.py", line 132, in websocket_handshake
rasa-production_1  |     raise ServerError(msg, status_code=500)
rasa-production_1  | sanic.exceptions.ServerError: Failed to open a WebSocket connection.

Using sanic 21.6.0 and python-engineio 4.3.1 works.

I see something similar with Rasa 3.4.0 from the official docker image (rasa/rasa:3.4.0-full) and recent versions of FF and Chrome using the web widget Rasa recommends in the docs, but it appears to only happen on refresh. Start a chat, works fine, hit refresh, get this error server side:

rasa-rasa-1  | Exception occurred while handling uri: 'ws://127.0.0.1:5005/socket.io/?EIO=4&transport=websocket&sid=GCuxT_yUCL6z0xZYAAAG'
rasa-rasa-1  | Traceback (most recent call last):
rasa-rasa-1  |   File "handle_request", line 124, in handle_request
rasa-rasa-1  | sanic.exceptions.ServerError: Invalid response type None (need HTTPResponse)

Note that I do not get the The client is using an unsupported version of the Socket.IO or Engine.IO protocols message some other people saw for similar errors in forum threads I researched.

My credentials.yml settings for socketio are as follows:

socketio:
  user_message_evt: user_uttered
  bot_message_evt: bot_uttered
  session_persistence: true

Again, the initial chat works fine, this happens when refreshing the page. Perhaps it’s a new/different bug?

I’ve seen some people recommend Botfront but that project appears to be dead.

This fix is not released yet and will be released in 3.1

It’s now fixed in the python-engineio repo, I’ve just asked for a pypi release

@Italosayan It is 3.7.7

I made some investigation and here are the results: Unfortunately, we have to wait for python-engineio to get fixed (https://github.com/miguelgrinberg/python-engineio/issues/251) because we made a bunch of changes to how we use sanic, and downgrading it to 21.6.0 makes little sense because in this case we would need to revert our changes, and that can potentially lead to issues with rasa-sdk as well.

We can speed things up a bit by fixing this issue: https://github.com/miguelgrinberg/python-engineio/issues/251