azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Web Search Operation returned an invalid status code 'Resource Not Found'

Open elwoujdi opened this issue 2 years ago • 2 comments

  • Package Name: azure-cognitiveservices-search-websearch
  • Package Version: 2.0.0
  • Operating System: Microsoft Windows 11 Home
  • Python Version: 3.12.2

Describe the bug My endpoint https://api.bing.microsoft.com does not work with the azure-sdk-for-python. I get this error when I make a search: azure.cognitiveservices.search.websearch.models._models_py3.ErrorResponseException: Operation returned an invalid status code 'Resource Not Found'

From my understanding, the endpoint has changed overtime and the new endpoint isn't working with the newest version of azure-cognitiveservices-search-websearch.

To Reproduce Steps to reproduce the behavior:

  1. Download the package
  2. Follow this documentation to make a query: Quickstart: Use a Bing Web Search Python client library image
  3. Run the snippet to create a web client

Expected behavior A clear and concise description of what you expected to happen.

    web_data = client.web.search(query=query)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    raise models.ErrorResponseException(self._deserialize, response)
azure.cognitiveservices.search.websearch.models._models_py3.ErrorResponseException: Operation returned an invalid status code 'Resource Not Found'

Proposition to fix the issue In the file azure/cognitiveservices/search/websearch/_configuration.py modify this line from:

base_url = '{Endpoint}/bing/v7.0'

to:

base_url = '{Endpoint}/v7.0'

TEMPORARY SOLUTION Add the line client.config.base_url = '{Endpoint}/v7.0' right after creating the client. This will fix the endpoint Exemple:

client = WebSearchClient(endpoint="https://api.bing.microsoft.com", credentials=CognitiveServicesCredentials(subscription_key))
client.config.base_url = '{Endpoint}/v7.0' # Temporary change to fix the error
web_data = client.web.search(query=query)

elwoujdi avatar Mar 25 '24 17:03 elwoujdi

Thanks for the feedback, we’ll investigate asap.

xiangyan99 avatar Mar 25 '24 22:03 xiangyan99

This package is no longer being maintained. Please refer to the samples in the Bing Search for Python repo instead.

For additional support, please open a new issue in the Issues section of the Microsoft Bing Search SDK for Python repo.

xiangyan99 avatar Aug 01 '24 16:08 xiangyan99