I’m currently deploying a Rasa chatbot to Okteto Cloud and I’m encountering this error:
ImportError: cannot import name ‘CLOSED’ from ‘websockets.connection’ (/usr/local/lib/python3.10/site-packages/websockets/connection.py)
Just to provide some context, I’m using Rasa version 3.5.1 and Python version 10.0.0. The error message appears when I run the ‘okteto up’ command.
I’ve attempted to fix the error by reinstalling the websockets library and checking all the dependencies to ensure they’re up to date, but the error still persists. I’m hoping someone might have some insight into what could be causing this issue or any suggestions on how to resolve it. Any help would be greatly appreciated. Thanks in advance!
From the error it seems like it might be a syntax or versioning error. Do you have a repository or relevant code sample you can share to help us understand the issue you are running into?
Hey @ramiro , thanks for welcoming me to this amazing community!
Here is my okteto file:
name: real-estate
# The build section defines how to build the images of your development environment
# More info: https://www.okteto.com/docs/reference/manifest/#build
build:
# You can use the following env vars to refer to this image in your deploy commands:
# - OKTETO_BUILD_RASA_ACTIONS_SERVER_REGISTRY: image registry
# - OKTETO_BUILD_RASA_ACTIONS_SERVER_REPOSITORY: image repo
# - OKTETO_BUILD_RASA_ACTIONS_SERVER_IMAGE: image name
# - OKTETO_BUILD_RASA_ACTIONS_SERVER_SHA: image tag sha256
rasa-actions-server:
context: .
dockerfile: Dockerfile
image: okteto.dev/rasa-server-bot:latest
# You can use the following env vars to refer to this image in your deploy commands:
# - OKTETO_BUILD_RASA_SERVER_REGISTRY: image registry
# - OKTETO_BUILD_RASA_SERVER_REPOSITORY: image repo
# - OKTETO_BUILD_RASA_SERVER_IMAGE: image name
# - OKTETO_BUILD_RASA_SERVER_SHA: image tag sha256
rasa-server:
context: .
dockerfile: Dockerfile
image: okteto.dev/rasa-server-bot:latest
# The deploy section defines how to deploy your development environment
# More info: https://www.okteto.com/docs/reference/manifest/#deploy
deploy:
compose:
file: docker-compose.yml
# The dependencies section defines other git repositories to be deployed as part of your development environment
# More info: https://www.okteto.com/docs/reference/manifest/#dependencies
# dependencies:
# - https://github.com/okteto/sample
# The dev section defines how to activate a development container
# More info: https://www.okteto.com/docs/reference/manifest/#dev
dev:
rasa-actions-server:
image: okteto.dev/rasa-server-bot:latest
command:
- bash
- -c
- rasa run actions
sync:
- actions:/app/actions
forward:
- 5055:5055
rasa-server:
image: okteto.dev/rasa-server-bot:latest
command:
- sh
- -c
- bash -c "rm -rf models/* && rasa train && rasa run --enable-api --cors \"*\" --debug"
sync:
- actions:/app/actions
- data:/app/data
forward:
- 5006:5005
This is my docker file
FROM python:3.10.0-buster AS BASE
RUN apt-get update \
&& apt-get --assume-yes --no-install-recommends install \
build-essential \
curl \
git \
jq \
libgomp1 \
vim
WORKDIR /app
# upgrade pip version
RUN pip install --no-cache-dir --upgrade pip
RUN pip install rasa==3.5.1
ADD config.yml config.yml
ADD domain.yml domain.yml
ADD credentials.yml credentials.yml
ADD endpoints.yml endpoints.yml
File "/usr/local/lib/python3.10/site-packages/sanic/server/protocols/websocket_protocol.py", line 3, in <module>
from websockets.connection import CLOSED, CLOSING, OPEN
ImportError: cannot import name 'CLOSED' from 'websockets.connection' (/usr/local/lib/python3.10/site-packages/websockets/connection.py)
exit status 1
x Command execution failed: process exited with status 1
Thanks for providing the code! I was able to reproduce and by googling the error I’ve found this stack-overflow post that suggests to pip install websockets==10.0, so I added ADD pip install websockets==10.0 and it did the trick
This is not the full solution though, as I’m now hitting some other error like ModuleNotFoundError: No module named 'actions'. I think this is due to the Dockerfile not copying anything like source files or requirements.txt for dependencies
I suggest you research more about Build your Python image and what files does rasa actually need, since there’s where these errors arise
Thanks for responding! I checked out the StackOverflow post you mentioned and attempted to resolve the issue by downgrading my websockets version to 10.0, but unfortunately, even after adding ADD pip install websockets==10.0 to my Dockerfile, I still encountered the same error. I’m currently stuck and hoping to find a solution soon. Thank you.
regarding the last proposal (ImportError: cannot import name 'CLOSED' from 'websockets.connection' - #4 by AgustinRamiroDiaz), you should add the instruction as RUN pip install websockets==10.0 instead of ADD pip install websockets==10.0. It seems to be a dependency issue of your app. Can you confirm that the Dockerfile is correct by trying to build and deploy a container with your app locally using docker build/run?