首页 > 解决方案 > sanic.exceptions.MethodNotSupported:方法 GET 不允许用于 URL /model/parse

问题描述

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

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

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

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

这是index.html文件

<form class="" action="" method="post">
    {% csrf_token %}
    <input type="text" name="message">
    <button type="submit" name="button">Send</button>
</form>

当用户在输入区域输入消息并点击发送时,该视图应该运行

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')

但是当我点击发送按钮时,我得到一个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 文档中指示的步骤进行操作。

标签: pythondjangohttp-status-code-405rasa-nlurasa

解决方案


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

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

URL /model/parse 不允许使用方法 GET

我建议您阅读以下内容: https ://www.geeksforgeeks.org/get-post-requests-using-python/


推荐阅读