question

BaronVonCornflake-6611 avatar image
0 Votes"
BaronVonCornflake-6611 asked YutongTie-MSFT answered

Bing Search Python 3.x SDK not working, "Resource Not Found", wrong HTTPS request being created

I am trying to follow the Python 3.x example at https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/client-libraries?pivots=programming-language-python .

This curl example works for me:

 curl -H "Ocp-Apim-Subscription-Key: <my subscription key>" https://api.bing.microsoft.com/v7.0/search?q=dog

However, this code does not:

 #!/usr/bin/python
    
 from azure.cognitiveservices.search.websearch import WebSearchClient
 from msrest.authentication import CognitiveServicesCredentials
    
 if __name__ == '__main__':
    
     subscription_key = '<my subscription key>'
     endpoint = 'https://api.bing.microsoft.com/'
    
     client = WebSearchClient(endpoint=endpoint, credentials=CognitiveServicesCredentials(subscription_key))
    
     web_data = client.web.search(query="dog")


I get :

   File "/usr/local/lib/python3.6/site-packages/azure/cognitiveservices/search/websearch/operations/_web_operations.py", line 371, in search
     raise models.ErrorResponseException(self._deserialize, response)
 azure.cognitiveservices.search.websearch.models._models_py3.ErrorResponseException: Operation returned an invalid status code 'Resource Not Found'

I added some logging to
_web_operations.py to reveal that

  1. Ocp-Apim-Subscription-Key is not being added to the headers, and

  2. The base URL that is being generated is https://api.bing.microsoft.com/bing/v7.0/search instead of https://api.bing.microsoft.com/v7.0/search .


Am I using the SDK incorrectly?

Thanks!

azure-bing-web
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YutongTie-MSFT avatar image
0 Votes"
YutongTie-MSFT answered

Hello,

Thanks for reporting your issue. This error seems to be due to the recent migration of the service from cognitive services to Microsoft Bing, our team is aware of the same and are working to update the SDKs accordingly. You can use the existing keys directly with the REST API to get the correct response. We understand that this could be a frustrating experience until the SDKs are updated, we will update this issue with more details as soon as we have a fix.

https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/python

Please changed the search_url to https://api.bing.microsoft.com/v7.0/search in above document.


Regards,
Yutong

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.