python - 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 文档中指示的步骤进行操作。
解决方案
为了回答您的问题,我将简单地强调您问题的两行:
requests.get(" http://localhost:5005/model/parse "
和
URL /model/parse 不允许使用方法 GET
我建议您阅读以下内容: https ://www.geeksforgeeks.org/get-post-requests-using-python/
推荐阅读
- php - PHP 无法断言两个字符串相等
- python - Colab 上的 TensorFlow v1,未找到 tf.contrib 模块
- android - 文件未在 android 内部存储中创建
- java - 我可以在 Java 的旧版本中对 2 个案例使用相同的数字吗?
- php - 使用 phpMyAdmin 彻底卸载 XAMPP
- c++ - 用于 RGB 到 HSB 转换的 C++ 程序中的错误
- javascript - 类型“事件”不可分配给类型“字符串”
- sorting - 使用随机选择指数或中位数快速选择?
- r - 将数据分成多个时间序列 R
- reactjs - Django重定向或反应历史?