【问题标题】:Rasa bot bad request and cors proxy issueRasa bot 错误请求和 cors 代理问题
【发布时间】:2019-09-06 03:43:00
【问题描述】:

Rasa 核心版本 13.7 nlu 版本 14.6 操作系统视窗 10 python 3.5版

我创建了 rasa 聊天机器人并训练了 nlu 以及对话模型。我已经成功地在控制台中运行了这个机器人,但是当我们尝试将它作为 http 服务器运行时,我们得到一个 cors 代理错误,如下所示 我们用来运行服务器的命令是

  • python -m rasa_core.run -d models/dialogue -u models/nlu/default/stem_nlu --enable_api --credentials credentials.yml --cors "*" 我也试过了
  • python -m rasa_core.run -d models/dialogue -u models/nlu/default/stem_nlu --enable_api --credentials credentials.yml --cors "*" -c rest 没有运气

    我也试过了

    • python -m rasa_core.run -d models/dialogue -u models/nlu/default/stem_nlu --enable_api --credentials credentials.yml --cors "*" -c rest 没有运气 我尝试通过浏览器和邮递员发送请求到

      localhost:5005/conversations/deafult/respond 我得到了 { “代码”:400, “细节”: { “在”:“查询”, “参数”:“查询” }, “帮助”:空, "message": "缺少消息参数。", “原因”:“无效参数”, “状态”:“失败”, “版本”:“0.13.7” }

也试过了

       localhost:5005/webhooks/rest/webhook 

我明白了

     Bad Request
     The browser (or proxy) sent a request that this server could not understand.

bot服务器显示

       options 127.0.0.1 - - [2019-04-15 17:34:30] "OPTIONS /webhooks/rest/webhook HTTP/1.1" 200 306 0.001031

然后发布请求

     127.0.0.1 - - [2019-04-15 17:34:30] "POST /webhooks/rest/webhook 
  HTTP/1.1" 400 352 0.000000

我们使用的脚本如下 $(document).ready(function(){

$("#button").click(function(){
var message=document.getElementById("message").value;
 console.log(message);
$.ajaxSetup({
 headers: {"Content-Type": "application/json"}
 });

$.ajax({
 url: "http://localhost:5005/webhooks/rest/webhook",
 type: "POST",
 data: '{ "sender": message}'
 }).done(function(data) {

    console.log(data);
 })

【问题讨论】:

    标签: node.js ajax rasa-nlu rasa-core


    【解决方案1】:

    明确提到 CORS 需要接受所有 API 调用。转到 RASA 项目文件夹并运行以下命令:

    rasa run --enable-api --cors "*"
    

    现在您不会看到 cors 错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 2015-06-05
      • 2018-11-19
      • 2020-10-12
      • 2018-08-29
      • 2019-04-17
      相关资源
      最近更新 更多