c# - 操作返回无效状态代码 'Forbidden` 。机器人框架 v4

标签 c# azure botframework azure-language-understanding

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

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

因此,我将订阅 key 更改为 azure 生成的 key 之一,但仍然出现相同的错误。我尝试重置创作 key 仍然相同,并删除我的 luis.ai 帐户并创建一个新帐户。 (仍然是同一电子邮件,因为这是登录 azure 门户的电子邮件。)并且仍然相同。

以下是一些图片供引用和错误。

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

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

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

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

这里直接在 URL 中测试时工作正常。 enter image description here

供引用:

azure 门户 enter image description here

路易斯.ai enter image description here

和错误 enter image description here

我如何在机器人中添加路易斯。 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 天了。谢谢!

最佳答案

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

默认情况下,您的代码会在此部分(第二行)中查找 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 机器人如何使用 key 即将发生一些变化,但这些变化可能需要一个月或更长时间。

或者,您可以更改:

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

至:

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

注意:如果您进行其中任何一项更改,LUIS 只能进行查询(这通常没问题),因为创作 key 可以执行其他所有操作(请参阅下面的引用资料)

引用文献

这些对您来说并不重要,而对其他可能遇到此问题的人来说则更重要。

Authoring vs. Endpoint Keys

Key Limits

Troubleshooting LUIS 403 Errors

关于c# - 操作返回无效状态代码 'Forbidden` 。机器人框架 v4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55012070/

相关文章:

c# - 在 C# 中为 Windows Mobile App 创建一个文本文件

azure - Terraform Incapsula 提供程序无法创建自定义证书资源

azure - ETL 文件合并失败 (0x80070006)

azure - 如何在 IIS 上托管 BOT Framework V4 BOT

node.js - Chatbot 消息不会显示在 Facebook Messenger 聊天头像中

c# - 我的 C# 类中的相对路径如何与 NUnit 3.x 一起使用?

c# - WPF DocumentViewer - 无需确认即可打印

c# - 抓取http请求并生成c#代码的工具

Azure 静态出站专用 IP

botframework - Conversation.Id 是唯一的吗? ServiceUrl 已更改?