Closed epomatti closed 4 years ago
@ramya-rao-a I have checked the provided steps and also my previous projects and created new projects and tested it. The service is returning the same error as "Access denied due to invalid subscription key or wrong API endpoint".
I have validated the values with the portal. The URL/Endpoint, headers are all the same. When I try using the portal, it is suceeding. In our SDK it is failing. I have also validated with previous SDK releases. All of them report the same error.
I think the service team must take a look at this issue since I do not find any issue with our side.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @areddish, @tburns10.
@areddish, @tburns10,
The latest package version is 5.1.1, but all that included was a change in the readme file.
The previous version 5.1.0 released 24 days ago had the changes from re-generating the package for the swagger update made in https://github.com/Azure/azure-rest-api-specs/pull/9522. At this time, it was working as expected. Something must have changed in the service between then and now for this issue to occur.
Can you please investigate?
The issue is with the credentials class that is being used. CustomVision doesn't use CognitiveServicesCredentials
as that has a hard coded header value that is not compatible with our API. You are using the correct credentials class in the C# example, which is why it works. You need to use the same credentials class for your JavaScript code - ApiKeyCredentials
. For example:
import { TrainingAPIClient } from "@azure/cognitiveservices-customvision-training";
const { ApiKeyCredentials} = require("@azure/ms-rest-azure-js");
const credentials = new ApiKeyCredentials({ inHeader: { "Training-key": trainingKey } });
const client = new TrainingAPIClient(credentials, "https://eastus.api.cognitive.microsoft.com");
const projects = client.getProjects()
For a more detailed sample take a look at our Quickstart For JavaScript
@areddish thanks, I got my sample from the official @azure/cognitiveservices-customvision-training npm package documentation, we need to fix that:
//. ..
const cognitiveServiceCredentials = new CognitiveServicesCredentials(customVisionTrainingKey);
const client = new TrainingAPIClient(cognitiveServiceCredentials, customVisionTrainingEndPoint);
// ...
I tried running your code but I'm getting an error: TypeError: ApiKeyCredentials is not a constructor
It also printed my key in the console. Is it possible to implement in a way that this can't happen?
@epomatti My apologies, I copied the imports from your example and didn't notice that my imports are using a different msRest package.
import { ApiKeyCredentials } from "@azure/ms-rest-js";
@areddish I didn't see it as well :grin: It works. I forked it and sent this pull request to reflect that change in the documentation.
Anything that can be done about the key being printed in the console when an exception occurs?
Thanks @areddish! Has this always been the case or any recent change in the service?
Thanks for the PR @epomatti!
@sarangan12, Any questions you have for @areddish?
@epomatti What exception caused the key to print into the console? The above screen shot is a code generation/transpile error that is dumping the line of code. That would be expected as it's a dev environment thing using node or tsc.
@ramya-rao-a A few changes back (few months) we aligned with the cognitive services to use the credentials classes. But it's only been ApiKeyCredentials. It looks like the npm doc example has been wrong for years (several versions).
@areddish you're right, I hardcoded it to make it short and that obviously will be printed (*facepalm).
I'm trying to connect to my Cognitive Services resource but I'm getting the following error:
I created the the resource with kind
CognitiveServices
like this:Using kind
CustomVision.Training
didn't work too.I have already looked at this answer but it is no the same problem. I believe I am entering the correct credentials and endpoint.
I checked both Azure Portal and customvision.ai resource, I'm using the correct URL and key, but it is not working.
I even tried reseting the key but also it had no effect.
I was also able to run it using the REST API and also the C# SDK and it is working.