操作返回了无效的状态代码“Forbidden”。机器人框架 v4

Operation returned an invalid status code 'Forbidden`. Botframework v4

所以我在 Azure 中创建了一个机器人并下载了它。来自 LUIS 的免费 1000 次调用已达到上限。我在 azure 门户中创建了一个订阅(我确实做了一些 docker 容器)。按照 this guide 直到第 6 步。当我单击端点 url 并直接在浏览器中查询时,它工作正常。

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

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

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

我也尝试在 luis.ai 中测试它并得到了这个结果。

但是当我检查它时它被设置为新资源。

这是通过 Bot 模拟器添加 luis 后的 bot 文件的图片。它具有相同的创作密钥和订阅密钥(仍然被禁止)

所以我现在用订阅密钥更改了它(仍然被禁止)。

此处直接在URL中测试时正常工作。

供参考:

蔚蓝门户

luis.ai

和错误

我如何在机器人中添加 luis。

这是机器人服务的代码。

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 天了。谢谢!

感谢您提供所有图片。这是一个巨大的帮助!问题是:

默认情况下,您的代码会在本节(第二行)中查找 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 替换为您的 endpointKey 之一(它们以 12ccc...b575... 开头)。

我理解您对此的困惑,尤其是因为这需要您在 authoringKey 属性 中添加 endpointKey。我知道 LUIS 机器人使用密钥的方式即将发生一些变化,但这些变化可能需要一个月或更长时间。

或者,您可以更改:

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

至:

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

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

参考资料

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

Authoring vs. Endpoint Keys

Key Limits

Troubleshooting LUIS 403 Errors