【问题标题】:sanic.exceptions.MethodNotSupported: Method GET not allowed for URL /model/parsesanic.exceptions.MethodNotSupported:方法 GET 不允许用于 URL /model/parse
【发布时间】:2020-01-23 03:07:56
【问题描述】:

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

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

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

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

这是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 documentation 中指示的步骤进行操作。

【问题讨论】:

  • 你打电话到这里response = requests.get("http://localhost:5005/model/parse",params={"q":user_message}) 你为它定义了路线吗
  • 我不这么认为。你能告诉我怎么做吗?

标签: python django http-status-code-405 rasa-nlu rasa


【解决方案1】:

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

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

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

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

【讨论】:

  • 您可以为您提供的链接添加一些上下文吗?可能是链接在某处断开。
猜你喜欢
  • 2019-06-27
  • 2021-07-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-23
  • 1970-01-01
  • 2016-12-12
  • 2018-11-12
  • 1970-01-01
相关资源
最近更新 更多