[英]“Operation returned an invalid status code 'Forbidden'” error on LUIS call
[英]Operation returned an invalid status code 'Forbidden`. Botframework v4
所以我在 azure 中创建了一个机器人并下载了它。 来自 LUIS 的免费 1000 次调用已达到上限。 我在 azure 门户中创建了一个订阅(我确实做了一些 docker 容器)。 遵循本指南直到第 6 步。当我单击端点 url 并直接在浏览器中查询时,它工作正常。
我通过 Bot Emulator 将它添加到机器人中,方法是单击 + 登录服务并在那里添加机器人模型。 但是当我运行 bot 时,我收到标题错误。 我注意到在 .bot 文件中,bot 模拟器添加的创作密钥和订阅密钥是相同的。
所以我将订阅密钥更改为 azure 生成的密钥之一,但仍然出现相同的错误。 我尝试重置创作密钥仍然相同并删除我的 luis.ai 帐户并创建一个新帐户。 (仍然是相同的电子邮件,因为那是登录 azure 门户的那个。)而且还是一样。
这里有一些图片供参考和错误。
这是通过 Bot 模拟器添加 luis 后的 bot 文件的图片。 它具有相同的创作密钥和订阅密钥(仍然被禁止)
以供参考:
这是机器人服务的代码。
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...
开头的ad9c...
,这已达到其限制,您的机器人不断遇到 403 错误。
因此,在您的.bot
文件中,将该authoringKey
替换为您的endpointKey
之一(它们以12ccc...
或b575...
)。
我理解您对此的困惑,特别是因为这需要您将endpointKey
放在您的authoringKey
属性中。 我知道 LUIS 机器人使用密钥的方式即将发生一些变化,但这些变化可能需要一个月或更长时间。
或者,您可以更改:
var app = new LuisApplication(luis.AppId, luis.AuthoringKey, endpoint);
到:
var app = new LuisApplication(luis.AppId, luis.SubscriptionKey, endpoint);
注意:如果您进行这些更改中的任何一个,LUIS只能查询(通常很好),因为 Authoring Keys 执行其他所有操作(请参阅下面的参考)
这些对你来说并不像其他人可能遇到的那样多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.