不支持sanic.exceptions.MethodNotSupported:URL/model/par不允许使用GET方法

2024-04-24 00:55:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究一个rasa聊天机器人。为了训练聊天机器人,我将所有的训练数据添加到nlu.md文件中。我将这些故事添加到stories.md文件中。我配置了domain.yml文件,还创建了一些自定义操作,当用户提出特定问题时,bot应该运行这些操作。现在我用rasa列车命令训练聊天机器人。这在models文件夹中创建了一个压缩文件。在

我用以下命令启动了NLU服务器

rasa run --enable-api -m models/nlu-20190919-171124.tar.gz

对于前端,我使用django为聊天机器人创建一个web应用程序。在

这是index.html文件

^{pr2}$

当用户在输入区域中键入消息并单击send时,应该运行此视图

def index(request):
    if request.method == 'POST':
        user_message = request.POST['message']
        response = requests.get("http://localhost:5005/model/parse",params={"q":user_message})
        print(response)
        return redirect('home')

    else:
        return render(request, 'index.html')

但是当我点击send按钮时,我得到一个405 error。这是来自NLU服务器的完整错误消息

Traceback (most recent call last):
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/sanic/app.py", line 893, in handle_request
    handler, args, kwargs, uri = self.router.get(request)
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/sanic/router.py", line 407, in get
    return self._get(request.path, request.method, "")
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/sanic/router.py", line 446, in _get
    raise method_not_supported
sanic.exceptions.MethodNotSupported: Method GET not allowed for URL /model/parse

这是来自我的django服务器的消息。在

<Response [405]>

不知道我做错了什么。我按照rasa documentation中指示的步骤操作。在


Tags: 文件服务器消息messagegetindexreturnsanic
2条回答

为了回答您的问题,我将简单地强调您问题的两行:

requests.get("http://localhost:5005/model/parse"

以及

Method GET not allowed for URL /model/parse

我建议你读这个: https://www.geeksforgeeks.org/get-post-requests-using-python/

在URL conf中为/model/parse定义一个URL路径,以及一些用于获取数据或响应的视图函数。在

相关问题 更多 >