Rasa Websocket Connection with Python

[ I have edited the post as I tried to do too much too soon. This question now purely addresses handling an initial connection from Python to Rasa]

I am currently running Rasa in a Python 3.7.5 virtual environment, although will be in Docker once I am up and running. I have installed Rasa with Pip and I am using Rasa 1.7.0. Rasa server running on localhost:5005. Running on debug I can see the following available routes:

2020-02-13 14:36:56 DEBUG    rasa.core.utils  - Available web server routes: 
/webhooks/rasa                                     GET                            custom_webhook_RasaChatInput.health
/webhooks/rasa/webhook                             POST                           custom_webhook_RasaChatInput.receive
/webhooks/rest                                     GET                            custom_webhook_RestInput.health
/webhooks/rest/webhook                             POST                           custom_webhook_RestInput.receive
/socket.io                                         GET                            handle_request
/                                                  GET                            hello
/webhooks/socketio                                 GET                            socketio_webhook.health

I have set up my config.yml as follows:

socketio:
  user_message_evt: user_uttered 
  bot_message_evt: bot_uttered 
  session_persistence: false

rasa:
  url: "http://localhost:5005/api"

Please note that I have changed Rasa url port above from the default 5002 to 5005 because Rasa is running on 5005.

Okay so down to brass tacks, within a Python interpreter:

>>> uri
'ws://localhost:5005/socket.io'
>>> 
>>> import asyncio
>>> import websockets
>>> from bson import ObjectId
>>> 
>>> async def connect( websocket):
...     websocket.send(
...             {
...                     "session_id": ObjectId(),
...                     "user_uttered": "hello world!"
...             }
...     )
... 
>>> async def main():
...     async with websockets.client.connect( uri) as websocket:
...             await connect( websocket)

This fails with: websockets.exceptions.InvalidStatusCode: Status code not 101: 200

meanwhile in the Rasa logs:

2020-02-13 15:49:35 DEBUG    rasa.core.channels.socketio  - User 0f8c16fb30164be5a18e4e583a0987c5 connected to socketIO endpoint.
2020-02-13 15:50:55 DEBUG    rasa.core.channels.socketio  - User 0f8c16fb30164be5a18e4e583a0987c5 disconnected from socketIO endpoint.

So, to be clear, while the Python intrepeter fails immediately, the Rasa socketIO doesn’t terminate for another 80 seconds.

Anyone with any pointers on this?

I assume the failure is happening on the websocket.send call?

Can you comment out the rasa channel in your credentials.yml file? Are you running Rasa X

Sorry for late reply, I’d been on holiday and I haven’t been able to reproduce this issue. I can only imagine it was actually something blocking at my server side ( where my fulfillment action targets). All working now!