[BUG] ErrorResponseException / InsufficientAuthorization when specifying more than one 'responseFilter' value for Microsoft.Azure.CognitiveServices.Search.WebSearch Search
See original GitHub issueDescribe the bug
When using the Microsoft.Azure.CognitiveServices.Search.WebSearch.WebSearchClient
of the Microsoft.Azure.CognitiveServices.Search.WebSearch v2.0 NuGet package I can either specify no or one responseFilter value, however - since it is a List<string>
parameter type and its documentation states I can provide a list of response types I want to get, I tried just that - more than one (i.e. three as shown in the example below), but when making the call I get an Microsoft.Azure.CognitiveServices.Search.WebSearch.Models.ErrorResponseException
back stating that
Operation returned an invalid status code 'Forbidden'
Only these values are allowed: Webpages,Images,Videos,News,SpellSuggestions,entities,places,RelatedSearches,Computation,TimeZone,Translations
Microsoft.Azure.CognitiveServices.Search.WebSearch.Models.ErrorResponseException: Operation returned an invalid status code 'Forbidden'
at Microsoft.Azure.CognitiveServices.Search.WebSearch.Web.SearchWithHttpMessagesAsync(String query, String acceptLanguage, String pragma, String userAgent, String clientId, String clientIp, String location, Nullable`1 answerCount, String countryCode, Nullable`1 count, String freshness, String market, Nullable`1 offset, IList`1 promote, IList`1 responseFilter, String safeSearch, String setLang, Nullable`1 textDecorations, String textFormat, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.CognitiveServices.Search.WebSearch.WebExtensions.SearchAsync(IWeb operations, String query, String acceptLanguage, String pragma, String userAgent, String clientId, String clientIp, String location, Nullable`1 answerCount, String countryCode, Nullable`1 count, String freshness, String market, Nullable`1 offset, IList`1 promote, IList`1 responseFilter, String safeSearch, String setLang, Nullable`1 textDecorations, String textFormat, CancellationToken cancellationToken)
at AzureCognitiveSearch.Program.Main(String[] args) in D:\Development\Playground\AzureCognitiveSearch\AzureCognitiveSearch\Program.cs:line 63
See also:
However, my input responseFilter values are part of the list of allowed values.
Expected behavior Search returns results for the given responseFilter values
Actual behavior (include Exception or Stack Trace)
Operation returned an invalid status code 'Forbidden'
Only these values are allowed: Webpages,Images,Videos,News,SpellSuggestions,entities,places,RelatedSearches,Computation,TimeZone,Translations
Microsoft.Azure.CognitiveServices.Search.WebSearch.Models.ErrorResponseException: Operation returned an invalid status code 'Forbidden'
at Microsoft.Azure.CognitiveServices.Search.WebSearch.Web.SearchWithHttpMessagesAsync(String query, String acceptLanguage, String pragma, String userAgent, String clientId, String clientIp, String location, Nullable`1 answerCount, String countryCode, Nullable`1 count, String freshness, String market, Nullable`1 offset, IList`1 promote, IList`1 responseFilter, String safeSearch, String setLang, Nullable`1 textDecorations, String textFormat, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.CognitiveServices.Search.WebSearch.WebExtensions.SearchAsync(IWeb operations, String query, String acceptLanguage, String pragma, String userAgent, String clientId, String clientIp, String location, Nullable`1 answerCount, String countryCode, Nullable`1 count, String freshness, String market, Nullable`1 offset, IList`1 promote, IList`1 responseFilter, String safeSearch, String setLang, Nullable`1 textDecorations, String textFormat, CancellationToken cancellationToken)
at AzureCognitiveSearch.Program.Main(String[] args) in D:\Development\Playground\AzureCognitiveSearch\AzureCognitiveSearch\Program.cs:line 63
To Reproduce Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)
Run the following repro code:
try
{
var webSearchResponse = await new WebSearchClient(new ApiKeyServiceClientCredentials("Your API KEY HERE"))
.Web
.SearchAsync(
query: "COVID-19 Statistik Erlangen",
count: 50,
offset: 0,
market: "de-DE",
setLang: "DE",
//countryCode:
safeSearch: SafeSearch.Off,
location: $"lat:49.583332;long:11.016667;re:22;disp:Erlangen, Germany", // see https://docs.microsoft.com/en-us/rest/api/cognitiveservices-bingsearch/bing-web-api-v7-reference
responseFilter: new List<string>()
{
"WebPages",
"RelatedSearches",
"SpellSuggestions"
});
}
catch (Exception ex)
{
Console.WriteLine("ex.Message);
}
Environment:
- Name and version of the Library package used: Microsoft.Azure.CognitiveServices.Search.WebSearch 2.0
- Hosting platform or OS and .NET runtime version: Windows 10 .NET Core 3.1
- IDE and version : Visual Studio 16.7
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Thank you for your feedback. Tagging and routing to the team best able to assist.
This issue can still be reproduced as originally reported @KranthiPakala-MSFT.