Skip to content

[BUG]responseFilter parameter not encoded correctly in cognitiveServicesWebSearch #39703

@yidasanqian

Description

@yidasanqian

how to fix exception:

Caused by: com.microsoft.azure.cognitiveservices.search.websearch.models.ErrorResponseException: Status code 403, {"_type": "ErrorResponse", "errors": [{"_type": "Error", "code": "InsufficientAuthorization", "message": "Insufficient authorization to access requested resource.", "moreDetails":"Only these values are allowed: Webpages,Images,Videos,News,SpellSuggestions,entities,places,RelatedSearches,Computation,TimeZone,Translations", "parameter": "responseFilter", "value": "WebPages%2CImages%2CVideos" }]}
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.microsoft.rest.ServiceResponseBuilder.build(ServiceResponseBuilder.java:122)
	at com.microsoft.azure.AzureResponseBuilder.build(AzureResponseBuilder.java:56)
	at com.microsoft.azure.cognitiveservices.search.websearch.implementation.BingWebSearchImpl.searchDelegate(BingWebSearchImpl.java:200)
	at com.microsoft.azure.cognitiveservices.search.websearch.implementation.BingWebSearchImpl.access$000(BingWebSearchImpl.java:41)
	at com.microsoft.azure.cognitiveservices.search.websearch.implementation.BingWebSearchImpl$2.call(BingWebSearchImpl.java:187)
	at com.microsoft.azure.cognitiveservices.search.websearch.implementation.BingWebSearchImpl$2.call(BingWebSearchImpl.java:183)
	at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
	at retrofit2.adapter.rxjava.CallArbiter.deliverResponse(CallArbiter.java:120)
	at retrofit2.adapter.rxjava.CallArbiter.emitResponse(CallArbiter.java:102)
	at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:46)
	at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24)
	at rx.Observable.unsafeSubscribe(Observable.java:10327)
	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
	at rx.Observable.subscribe(Observable.java:10423)
	at rx.Observable.subscribe(Observable.java:10390)
	at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:443)
	at rx.observables.BlockingObservable.single(BlockingObservable.java:340)
	at com.microsoft.azure.cognitiveservices.search.websearch.implementation.BingWebSearchImpl$BingWebsSearchParameters.execute(BingWebSearchImpl.java:357)

code:

 SearchResponse searchResponse = client.bingWebs()
                .search()
                .withQuery(searchQuery.getKeywords())
                .withUserAgent(userAgent)
                .withClientId(searchQuery.getClientId())
                .withClientIp(requestIp)
                .withMarket(searchQuery.getMarket())
                .withCount(searchQuery.getCount())
                .withOffset(searchQuery.getOffset())
                .withResponseFilter(Arrays.asList(AnswerType.WEB_PAGES, AnswerType.IMAGES, AnswerType.VIDEOS))
                .withSafeSearch(SafeSearch.MODERATE)
                .execute();
        WebWebAnswer webAnswer = searchResponse.webPages();

gradle:

implementation 'com.microsoft.azure:azure:1.41.4'
implementation 'com.microsoft.azure.cognitiveservices:azure-cognitiveservices-websearch:1.0.2'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Cognitive ServicesbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions