Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.31k stars 1.96k forks source link

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

Open yidasanqian opened 5 months ago

yidasanqian commented 5 months ago

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'
github-actions[bot] commented 5 months ago

@alzimmermsft @jairmyree

github-actions[bot] commented 5 months ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

alzimmermsft commented 5 months ago

@weidongxu-microsoft re-routing your way as this appears to be a Management plane SDK

weidongxu-microsoft commented 5 months ago

@alzimmermsft

The error com.microsoft.azure.cognitiveservices.search.websearch appears come from "com.microsoft.azure.cognitiveservices:azure-cognitiveservices-websearch:1.0.2" https://mvnrepository.com/artifact/com.microsoft.azure.cognitiveservices/azure-cognitiveservices-websearch (I believe to be a data-plane lib)

Do we have a replacement on this lib in "com.azure" group?

(I am certain "com.microsoft.azure:azure" won't call "azure-cognitiveservices-websearch")

@yidasanqian

"com.microsoft.azure:azure" was deprecated years ago. https://github.com/Azure/azure-libraries-for-java?tab=readme-ov-file#this-repository-has-been-deprecated Please schedule the migration to https://aka.ms/azsdk/java/mgmt

yidasanqian commented 5 months ago

Bing API SDK can be found at: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cognitiveservices/ms-azure-cs-websearch/pom.xml

However, it is not included in the Migration steps for the azure-cognitiveservices-websearch library available at: https://aka.ms/azsdk/java/mgmt

weidongxu-microsoft commented 5 months ago

Bing API SDK can be found at: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cognitiveservices/ms-azure-cs-websearch/pom.xml

However, it is not included in the Migration steps for the azure-cognitiveservices-websearch library available at: https://aka.ms/azsdk/java/mgmt

No, it is not include in https://aka.ms/azsdk/java/mgmt. This is for the management-plane libs (the new ones would be in group "com.azure.resourcemanager".

I didn't find the new lib for azure-cognitiveservices-websearch in our SDK repo. That is what I am currently checking with Alan about (we may not have a new lib yet).