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
Ocp-Apim-Subscription-Keyis not being added to the headers, andThe base URL that is being generated is
https://api.bing.microsoft.com/bing/v7.0/searchinstead ofhttps://api.bing.microsoft.com/v7.0/search.
Am I using the SDK incorrectly?
Thanks!