操作返回了无效的状态代码'Forbidden`。 Botframework v4

问题描述 投票:2回答:1

所以我在azure中创建了一个bot并下载了它。来自LUIS的免费1000次电话达到了极限。我在azure portal中创建了一个订阅(我确实做了docker容器的东西)。跟随this guide直到第6步。当我点击端点网址并直接在浏览器中查询它工作正常。

我通过Bot Emulator将它添加到机器人中,点击+登录服务并在那里添加机器人模型。但是当我运行bot时,我得到了标题错误。我在.bot文件中注意到,bot模拟器添加的创作密钥和订阅密钥是相同的。

所以我将订阅密钥更改为azure生成的密钥之一,但仍然是相同的错误。我已经尝试重置创作密钥仍然相同并删除我的luis.ai帐户并创建了一个新帐户。 (仍然是同样的电子邮件,因为这是登录天蓝色门户网站的那个。)并且仍然相同。

这里有一些图片供参考和错误。

我也试过在luis.ai测试它并得到了这个结果。 enter image description here

但是当我检查它是否设置为新资源。 enter image description here

这是通过Bot仿真器添加luis后的bot文件的图片。它具有相同的创作密钥和订阅密钥(仍然禁止)enter image description here

所以我现在用订阅密钥(仍然禁止)更改它。 enter image description here

在URL中直接测试时,它可以正常工作。 enter image description here

以供参考:

天蓝色的门户网站enter image description here

luis.ai enter image description here

和错误enter image description here

我如何在机器人中添加luis。 enter image description here

这是机器人服务的代码。

using System;
using System.Collections.Generic;
using Microsoft.Bot.Builder.AI.Luis;
using Microsoft.Bot.Configuration;

namespace Microsoft.BotBuilderSamples
{
    public class BotServices
    {
        public BotServices(BotConfiguration botConfiguration)
        {
            foreach (var service in botConfiguration.Services)
            {
                switch (service.Type)
                {
                    case ServiceTypes.Luis:
                        {
                            var luis = (LuisService)service;
                            if (luis == null)
                            {
                                throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file.");
                            }

                            var endpoint = (luis.Region?.StartsWith("https://") ?? false) ? luis.Region : luis.GetEndpoint();
                            var app = new LuisApplication(luis.AppId, luis.AuthoringKey, endpoint);
                            var recognizer = new LuisRecognizer(app);
                            this.LuisServices.Add(luis.Name, recognizer);
                            break;
                        }
                }
            }
        }

        public Dictionary<string, LuisRecognizer> LuisServices { get; } = new Dictionary<string, LuisRecognizer>();
    }
}

我试图解决这个问题已经4天了。谢谢!

c# azure botframework luis
1个回答
2
投票

谢谢你的所有图片。这是一个巨大的帮助!这是问题所在:

默认情况下,您的代码在本节中查找AuthoringKey(第二行):

var endpoint = (luis.Region?.StartsWith("https://") ?? false) ? luis.Region : luis.GetEndpoint();
var app = new LuisApplication(luis.AppId, luis.AuthoringKey, endpoint);
var recognizer = new LuisRecognizer(app);
this.LuisServices.Add(luis.Name, recognizer);

由于你的.bot文件仍然将authoringKey设置为以ad9c...开头的那个,它已达到极限,你的机器人一直遇到403错误。

因此,在你的.bot文件中,将authoringKey替换为你的一个endpointKeys(它们以12ccc...b575...开头)。

我理解你对此的困惑,特别是因为这需要你在你的endpointKey财产中加入authoringKey。我知道LUIS机器人将如何使用密钥有一些变化,但那可能是一个月或更长时间。

或者,您可以更改:

var app = new LuisApplication(luis.AppId, luis.AuthoringKey, endpoint);

至:

var app = new LuisApplication(luis.AppId, luis.SubscriptionKey, endpoint);

注意:如果您进行了其中任何一项更改,LUIS只能查询(通常很好),因为创作密钥会执行其他所有操作(请参阅下面的参考资料)

References

这些对你来说并不像可能遇到过这种情况的其他人那么多。

Authoring vs. Endpoint Keys

Key Limits

Troubleshooting LUIS 403 Errors

© www.soinside.com 2019 - 2024. All rights reserved.