Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VisualSearch fails with Unauthorized despite valid key #7

Open
palenshus opened this issue Aug 5, 2022 · 2 comments
Open

VisualSearch fails with Unauthorized despite valid key #7

palenshus opened this issue Aug 5, 2022 · 2 comments

Comments

@palenshus
Copy link

palenshus commented Aug 5, 2022

I feel I must be missing something obvious here. I've been trying to follow the instructions at https://docs.microsoft.com/en-us/bing/search-apis/bing-visual-search/quickstarts/sdk/visual-search-client-library-csharp. I created a "Bing Search" service in Azure with the S9 tier which supports Visual Search. I went to the Keys and Endpoint section and copied the Key 1 out and put it in the below code, yet every time I run it I get Unauthorized:

{"code":"401","message": "Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}
var client = new VisualSearchClient(new Microsoft.Azure.CognitiveServices.Search.VisualSearch.ApiKeyServiceClientCredentials("<key>"));

ImageInfo ImageInfo = new ImageInfo(url: "https://media.vanityfair.com/photos/5d9f5be40fa2040008f28470/4:3/w_1776,h_1332,c_limit/always-sunny-in-philadelphia-hangs-in-there.jpg");
VisualSearchRequest VisualSearchRequest = new VisualSearchRequest(imageInfo: ImageInfo);

var result = await client.Images.VisualSearchMethodAsync(knowledgeRequest: JsonConvert.SerializeObject(VisualSearchRequest));

The instructions don't say anything about setting an endpoint, but I tried that too, setting the Endpoint property from the one in my Keys and Endpoint page:

client.Endpoint = "https://api.bing.microsoft.com/";

But that just result in a NotFound error.

I was able to get it working by calling the REST api directly, so I know the key isn't the issue. For now I'm calling the REST API but it's a pretty kludgy API to call so I'd much prefer to use the SDK, especially since I can't get the REST code working when uploading an image instead of providing a URL: https://github.com/microsoft/bing-search-dotnet-samples/issues/4

Anyone have any idea what's going on? I tried both keys with no success. Here's a LINQPad repro of the issue: http://share.linqpad.net/c3p8vo.linq

@palenshus
Copy link
Author

I figured out the issue. The nuget SDK pointed to by the documentation is incorrect! It says to use the Microsoft.Azure.CognitiveServices.Search.VisualSearch package which is out-of-date, and has the old endpoint in it: https://api.cognitive.microsoft.com. I found that there's another SDK in nuget, Microsoft.Bing.Search.VisualSearch which has the correct endpoint: https://api.bing.microsoft.com, but I can't find documentation anywhere pointing to that! That's pretty dang bad.

@rcastoro
Copy link

I have same trouble, NotAuthorized, when I point client to specific endpoint I get NotFound error. SDK broken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants