Web Search Operation returned an invalid status code 'Resource Not Found'
- 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:
- Download the package
- Follow this documentation to make a query: Quickstart: Use a Bing Web Search Python client library
- 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)
Thanks for the feedback, we’ll investigate asap.
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.