Botframework-solutions: Error adding an additional knowledge base ""Access denied due to invalid subscription key"

Created on 27 May 2019  路  6Comments  路  Source: microsoft/botframework-solutions

Project

Name: Virtual Assistant

Language: C#

Description

Following the guide here when running step 3 (.\Deployment\Scripts\update_cognitive_models.ps1 -RemoteToLocal) I get the following:

Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key.

Further down there is also another error about not being able to parse stdin but I suspect this could be caused by the first error.

To Reproduce

  1. Create Virtual Assistant using this guide.
  2. Create a new knowledge base in the QnA Maker portal as detailed in the last sentence of step 1 in this guide
  3. Update cognitiveModels.json with a new entry in the knowledgebases section as per step 2 of the above guide.
  4. Run .\Deployment\Scripts\update_cognitive_models.ps1 -RemoteToLocal from pwsh.exe in the project directory.
  5. Local files are created but publishing to LUIS fails.

Expected behavior

Publishing to LUIS to succeed.

Screenshots

Azure resources
https://i.imgur.com/SsDrPRY.png
LUIS apps
https://i.imgur.com/6QqmINZ.png
Console
https://i.imgur.com/HUTuNYd.png

Additional context

Additional information:

  • I noticed that the script continues to process the other parts but the error message was appearing early on (during the luis export step), so I added the a line above this line to include my LUIS subscription key (--subscriptionKey --subscriptionKey $luisApp.subscriptionkey `).

    • But this didn't fix the issue.

  • I also noticed that by default the subscriptionKey value is the same as that of the authoringKey when usually it should be the value of an end point key as described here - but I don't think it matter's for this scenario because I created an endpoint key, updated my cognitive models JSON, and ran the script again (with the above change including the subscription key).

    • This also didn't fix the issue.

In addition to the above as per this issue and this issue I am using the correct LUIS portal for where my resources are deploy (australiaeast). I verified this by checking the IDs and names from the congitive services file against those in my LUIS portal.

Console output:

PS C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1> .\Deployment\Scripts\update_cognitive_models.ps1 -RemoteToLocal
> Getting config file ...
> Updating local general.lu file ...

     Update available 1.2.0 -> 1.3.1
     Run npm i -g ludown to update.

Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key.

LUIS Command Line Interface - 漏 2018 Microsoft Corporation

Exports a LUIS application to JSON format.

Usage:
luis export version --appId <string> --versionId <string>

Command arguments are:
 --appId <string> (required)    The application ID.
 --versionId <string>           The version ID.
 (required)

Configuration and Overrides:
 --appId                        Specifies the public LUIS application id. Overrides the .luisrc value
                                and the LUIS_APP_ID environment variable.
 --authoringKey                 Specifies the LUIS authoring  key (from luis.ai portal user settings
                                page). Overrides the .luisrc value and the LUIS_AUTHORING_KEY
                                environment variable.
 --subscriptionKey              Specifies the LUIS subscriptionKey. Overrides the .luisrc value and
                                the LUIS_SUBSCRIPTION_KEY environment variable.
 --versionId                    Specifies the version id. Overrides the .luisrc value and the
                                LUIS_VERSION_ID environment variable.
 --region                       Specifies the authoring region for all requests.
                                [westus|westeurope|australiaeast] Overrides the .luisrc value and the
                                LUIS_REGION environment variable.
 --stdin                        Pull in service keys from stdin in the format of that is the output
                                of: msbot get service
 --prefix                       Appends [luis-apis] prefix to all messages

Global Arguments:
 --help,    -h                  Prints this help file.
 --version, -v                  Prints the version of this cli tool
 --force,   -f                  Do not prompt for confirmation, force the operation
 --!                            Dumps all documented commands to the console with descriptions

Sorry, unable to parse stdin as JSON!

 {}


Stopping further processing.
> Updating local chitchat.lu file ...

     Update available 1.2.0 -> 1.3.1
     Run npm i -g ludown to update.
> Updating local faq.lu file ...

     Update available 1.2.0 -> 1.3.1
     Run npm i -g ludown to update.
> Updating local microsoft-faq.lu file ...

     Update available 1.2.0 -> 1.3.1
     Run npm i -g ludown to update.
> Updating dispatch model ...
> Running LuisGen ...
> Done.
PS C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1>

Update Cognitive Models output:

Exporting services for dispatch...
Exporting ms-virt-assistanten_general LUIS application...
Exporting chitchat QnA kb...
Exporting faq QnA kb...
Creating dispatch LUIS model json...
Creating training data...
WARNING: Number of samples in 'C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\data\_experiments\model_007\train.txt' that were used by multiple categories: 9
WARNING: very few samples (breaking-point for debugging purpose), foldSize=0.6, foldsCount=5, Samples.Length=3, category=None, TrainingSamplesCount=2, TestingSamplesCount=1
WARNING: Number of samples in 'C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\data\_experiments\model_007\cv5\fold000\train.txt' that were used by multiple categories: 7
WARNING: Number of samples in 'C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\data\_experiments\model_007\cv5\fold001\train.txt' that were used by multiple categories: 8
WARNING: Number of samples in 'C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\data\_experiments\model_007\cv5\fold002\train.txt' that were used by multiple categories: 4
WARNING: Number of samples in 'C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\data\_experiments\model_007\cv5\fold002\test.txt' that were used by multiple categories: 1
WARNING: Number of samples in 'C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\data\_experiments\model_007\cv5\fold003\train.txt' that were used by multiple categories: 4
WARNING: Number of samples in 'C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\data\_experiments\model_007\cv5\fold004\train.txt' that were used by multiple categories: 5
Updating ms-virt-assistanten_Dispatch model...
Importing ms-virt-assistanten_Dispatch model...
Training ms-virt-assistanten_Dispatch model...
Setting up intents to child services mapping for ms-virt-assistanten_Dispatch...
Publishing ms-virt-assistanten_Dispatch model...
Training ms-virt-assistanten_general...
Publishing ms-virt-assistanten_general...
Writing summary file ('test_prediction')...
Please review your updated dispatch model in C:\Users\xxx\Documents\repos\xxx\VirtualAssistant1\VirtualAssistant1\VirtualAssistant1\Deployment\Resources\Dispatch\Summary.html

Let me know if there is any other information that I can provide.

Bug

Most helpful comment

Thanks for providing so much detail, really helpful.

I suspect this call to luis to export version might be at fault as it's not passing the region so probably defaulting to westus hence the access denied.

 # Update local LU files based on hosted models
        foreach ($luisApp in $models.languageModels)
        {
            Write-Host "> Updating local $($luisApp.id).lu file ..."
            luis export version `
                --appId $luisApp.appid `
                --versionId $luisApp.version `
                --authoringKey $luisApp.authoringKey | ludown refresh `
                --stdin `
                -n "$($luisApp.id).lu" `
                -o $(Join-Path $luisFolder $langCode)
        }

Try adding this line under --versionId key in your update_cognitive_models.ps1 file to see if that alleviates the issue?

--region $luisApp.region `

e.g.:

 Write-Host "> Updating local $($luisApp.id).lu file ..."
            luis export version `
                --appId $luisApp.appid `
                --versionId $luisApp.version `
        --region $luisApp.region `
                --authoringKey $luisApp.authoringKey | ludown refresh `
                --stdin `
                -n "$($luisApp.id).lu" `
                -o $(Join-Path $luisFolder $langCode)

All 6 comments

Thanks for providing so much detail, really helpful.

I suspect this call to luis to export version might be at fault as it's not passing the region so probably defaulting to westus hence the access denied.

 # Update local LU files based on hosted models
        foreach ($luisApp in $models.languageModels)
        {
            Write-Host "> Updating local $($luisApp.id).lu file ..."
            luis export version `
                --appId $luisApp.appid `
                --versionId $luisApp.version `
                --authoringKey $luisApp.authoringKey | ludown refresh `
                --stdin `
                -n "$($luisApp.id).lu" `
                -o $(Join-Path $luisFolder $langCode)
        }

Try adding this line under --versionId key in your update_cognitive_models.ps1 file to see if that alleviates the issue?

--region $luisApp.region `

e.g.:

 Write-Host "> Updating local $($luisApp.id).lu file ..."
            luis export version `
                --appId $luisApp.appid `
                --versionId $luisApp.version `
        --region $luisApp.region `
                --authoringKey $luisApp.authoringKey | ludown refresh `
                --stdin `
                -n "$($luisApp.id).lu" `
                -o $(Join-Path $luisFolder $langCode)

Thanks for this @darrenj. I haven't had a chance to try it out yet as I ran out of credit on my Azure subscription. I'm hoping to try it today inside another subscription.

@darrenj deploying everything to westus seems to have works and as it is a test project I'm not too fussed about deploying to the correct region. Would you like me to raise an issue about the LUIS region not being used in the luis export version command or have you already done this internally? Feel free to close this issue now. 馃憤

edit

Sooo I jumped the gun. The update_cognitive_models.ps1 script ran "successfully" - without errors that is. But it didn't actually update my dispatcher or strongly typed class using LuisGen which the instructions state:

The final step is to update your Dispatcher and associated strongly typed class (LuisGen). We have provided the update_cognitive_models.ps1 script to simplify this for you.

I have tried with and without the -RemoteToLocal flag. If I include the flag then only the .lu file is created - the existing KBs also have a .qna file with them. If I run without the -RemoteToLocal flag then a .qna file is created for my new KB but the generated dispatch file and summary do not include the newly add KB intent. I have also checked that my KB is published.

Console output (tried different variations of the flag an also have manual changes in the script to output some extra information):

console

It is also interesting that my update_cognitive_models_log.txt has no mention of the newly added KB:

Exporting services for dispatch...
Exporting chitchat QnA kb...
Exporting faq QnA kb...
Creating dispatch LUIS model json...
Creating training data...
WARNING: Number of samples in 'C:\Users\mastan\Desktop\VirtualAssistant\MyAssistant1\MyAssistant1\Deployment\Resources\Dispatch\data_experiments\model_007\train.txt' that were used by multiple categories: 2
WARNING: Number of samples in 'C:\Users\mastan\Desktop\VirtualAssistant\MyAssistant1\MyAssistant1\Deployment\Resources\Dispatch\data_experiments\model_007\cv5\fold000\train.txt' that were used by multiple categories: 2
WARNING: Number of samples in 'C:\Users\mastan\Desktop\VirtualAssistant\MyAssistant1\MyAssistant1\Deployment\Resources\Dispatch\data_experiments\model_007\cv5\fold001\train.txt' that were used by multiple categories: 2
WARNING: Number of samples in 'C:\Users\mastan\Desktop\VirtualAssistant\MyAssistant1\MyAssistant1\Deployment\Resources\Dispatch\data_experiments\model_007\cv5\fold002test.txt' that were used by multiple categories: 1
WARNING: Number of samples in 'C:\Users\mastan\Desktop\VirtualAssistant\MyAssistant1\MyAssistant1\Deployment\Resources\Dispatch\data_experiments\model_007\cv5\fold003\train.txt' that were used by multiple categories: 1
WARNING: Number of samples in 'C:\Users\mastan\Desktop\VirtualAssistant\MyAssistant1\MyAssistant1\Deployment\Resources\Dispatch\data_experiments\model_007\cv5\fold004\train.txt' that were used by multiple categories: 2
Updating msag-test-va-boten_Dispatch model...
Importing msag-test-va-boten_Dispatch model...
Training msag-test-va-boten_Dispatch model...
Setting up intents to child services mapping for msag-test-va-boten_Dispatch...
Publishing msag-test-va-boten_Dispatch model...
Writing summary file ('test_prediction')...
Please review your updated dispatch model in C:\Users\mastan\Desktop\VirtualAssistant\MyAssistant1\MyAssistant1\Deployment\Resources\Dispatch\Summary.html

Here are the contents of my cognitivemodels.json file - the DocFAQ is the new KB that I added via the QnA Maker portal:

{
  "cognitiveModels": {
    "en": {
      "dispatchModel": {
        "type": "dispatch",
        "region": "westus",
        "subscriptionkey": "redacted",
        "name": "msag-test-va-boten_Dispatch",
        "appid": "bf4d398c-18e4-497c-94d5-2d7d1fb32ecc",
        "authoringkey": "redacted"
      },
      "knowledgebases": [
        {
          "id": "chitchat",
          "name": "chitchat",
          "kbId": "14eb5bee-924c-4321-97ae-2d0db66e3f85",
          "endpointKey": "redacted",
          "hostname": "https://msag-test-va-bot-qnahost.azurewebsites.net",
          "subscriptionKey": "redacted"
        },
        {
          "id": "faq",
          "name": "faq",
          "kbId": "e3b88ba4-8769-4744-858b-e72df6d10541",
          "endpointKey": "redacted",
          "hostname": "https://msag-test-va-bot-qnahost.azurewebsites.net",
          "subscriptionKey": "redacted"
        },
        {
            "id": "DocFAQ",
            "name": "DocFAQ",
            "kbId": "a6feed31-3fe1-4511-a2cf-22609f5d356b",
            "endpointKey": "redacted",
            "hostname": "https://msag-test-va-bot-qnahost.azurewebsites.net",
            "subscriptionKey": "redacted"
        }
      ],
      "languageModels": [
        {
          "id": "general",
          "name": "msag-test-va-boten_general",
          "region": "westus",
          "version": "0.1",
          "authoringkey": "redacted",
          "appid": "6631cd5c-1455-4a2c-91a2-db82ed313d7d",
          "subscriptionkey": "redacted"
        }
      ]
    }
  },
  "defaultLocale": "en-us"
}

I also can't see where in the update_cognitive_models.ps1 script that the strongly typed class gets updated but there is an example command at the top of the DispatchLuis.cs file which should get that sorted out.

In #1432 we have updated the script as it had an issue around updating dispatcher, good spot!

If you pull this down and replace your version I suspect this will resolve this issue for you.

Thanks @darrenj!

Just FYI when you run Run .\Deployment\Scriptsupdate_cognitive_models.ps1 ... in the cognitivemodels.json the endpoint url was for LUIS authoring and the region was also for the authoring luis region ... usually westus ... otherwise you get :

Failed to retrieve application data: Error: PermissionDenied

Was this page helpful?
0 / 5 - 0 ratings