Warnings about bing images search API

Hi,

Just to warn so that new learner will not spend time on this issue.

In 02_production.ipynb, the search_images_bing no longer work because after MS migrate the search API from cognitive service to bing search service, the cognitive SDK is not working.
See error : resource not found

Instead, we need to use REST API, see Quickstart: Search for images using the Bing Image Search REST API and Python - Azure Cognitive Services | Microsoft Docs

I redefine the function as below

def search_images_bing(subscription_key, search_term):
    search_url = "https://api.bing.microsoft.com/v7.0/images/search"
    headers = {"Ocp-Apim-Subscription-Key" : subscription_key}
    params  = {"q": search_term, "count": 150, "minWidth": 128, "minHeight": 128, "license": "public", "imageType": "photo"}
    response = requests.get(search_url, headers=headers, params=params)
    response.raise_for_status()
    search_results = response.json()
    return L(search_results["value"])
2 Likes