question

ac-5595 avatar image
0 Votes"
ac-5595 asked ajkuma-MSFT answered

Unable to retrieve images using ImageSearchClient

My requirement is to get images from the web. What I tried is -

  1. I created a Bing search resource to get keys and endpoint. I now have two keys for the endpoint - https://api.bing.microsoft.com/

  2. Ran the below code in a python notebook.

    from azure.cognitiveservices.search.imagesearch import ImageSearchClient as api
    from msrest.authentication import CognitiveServicesCredentials as auth

    key = <value of my key>

    client = api('https://api.bing.microsoft.com/', auth(key))
    p = client.images.search(query='grizzly bear', count=1, min_height=128, min_width=128)


  3. Last line gives a ErrorResponseException: Operation returned an invalid status code 'Resource Not Found' error.


Please advise.






azure-cognitive-searchazure-bing-image
· 1
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.

@ac-5595 I believe this error with the python packages is due to the recent migration of bing services from cognitive services to bing search services. The above mentioned endpoint with the key will work if used directly with REST API as these package clients needs to be updated to reflect the correct search bing endpoints.

0 Votes 0 ·

1 Answer

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

@ac-5595, Apologies for the delay!

For Azure cognitive search stand-point, create an instance of CognitiveServicesCredentials, and use it to instantiate the client, this way instead to isolate:

 client = ImageSearchClient(endpoint=subscription_endpoint, credentials=CognitiveServicesCredentials(subscription_key))

Kindly review for correctness, replace the values with this:
SUBSCRIPTION_KEY with a valid subscription key.
YOUR_ENDPOINT with your endpoint url in portal and remove the bing/v7.0 section from the endpoint.


Also, the Python implementation adds automatically the Bing version, refer to a similar discussion.

If you're using version 1.2.0 or below for the Bing Image Search client library, use ImageSearchAPI() instead of ImageSearchClient() to initialize your search client.

We have tagged bing-image, for receiving insights from the right experts.


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.