Docker部署Rasa遇SanicException:Blueprint命名格式无效求助
问题详情
我尝试在Docker镜像中安装Rasa,Dockerfile内容如下:
RUN pip3 install rasa==3.1.0 RUN pip3 install rasa-sdk==3.1.1 RUN pip3 install sanic RUN pip3 install sanic-cors RUN pip3 install sanic-validation
但创建容器时出现如下错误:
Traceback (most recent call last):
File "main.py", line 5, in from core.extentions.exceptions import blueprint as ext_exceptions
File "/rasa-app/core/extentions/exceptions.py", line 9, in blueprint = Blueprint('core.extentions.exceptions')
File "/usr/local/lib/python3.7/site-packages/sanic/blueprints.py", line 119, in init super().init(name=name)
File "/usr/local/lib/python3.7/site-packages/sanic/base/root.py", line 38, in init f"{class_name} instance named '{name}' uses an invalid "
sanic.exceptions.SanicException: Blueprint instance named 'core.extentions.exceptions' uses an invalid format. Names must begin with a character and may only contain alphanumeric characters, _, or -.
我尝试过使用以下命令安装,仍出现相同错误,更换多个Rasa版本也无法解决:
RUN pip install rasa RUN pip install rasa-sdk RUN pip install sanic RUN pip install sanic-cors RUN pip install sanic-validation
解决方案
这个错误和Rasa、Sanic的安装版本无关,问题出在Blueprint的命名格式不符合Sanic的要求:
错误原因:Sanic对Blueprint名称有严格格式限制——必须以字符开头,仅允许包含字母、数字、下划线
_或连字符-,而你的代码中使用了带句点.的名称core.extentions.exceptions,违反了该规则。修复操作:
- 打开
/rasa-app/core/extentions/exceptions.py文件,修改Blueprint初始化代码,将名称中的句点替换为下划线或连字符:# 使用下划线替换句点 blueprint = Blueprint('core_extentions_exceptions') # 或者使用连字符替换 # blueprint = Blueprint('core-extentions-exceptions') - 同步检查所有引用该Blueprint的代码(比如
main.py中的导入和注册逻辑),确保名称一致,避免出现匹配错误。
- 打开
验证结果:修改完成后重新构建Docker镜像并启动容器,即可解决该SanicException错误。
内容的提问来源于stack exchange,提问作者Rodrigo Torres Sánche

