Search_images_bing just returns [None]*150

Hi everyone! This is my first post here so I apologize if I’m asking this wrongly in some way.

I’m in Chapter 2 of the book, trying to follow along with the bears example. I’ve signed up for a Microsoft Azure account and am getting my API key(s) from their webpage that looks like this:

I’ve tried replacing the 'XXX' in the first cell under “Gathering Data” with either one of my keys, and while the key variable does seem to be set properly, I see this as the contents of ims after running the cell that uses search_images_bing and results.attrgot:

(#150) [None,None,None,None,None,None,None,None,None,None...]

I can confirm by running filter(lambda x: x, ims) that this list is all None.

The same issue occurs whether I try this in Paperspace or on my local Ubuntu machine. How can I resolve this? Or should I try a different image search service instead of Bing?

2 Likes

got the same issue on Paperspace!!

Same thing here. May be related to this? “… Bing Search APIs will be transitioning from Azure Cognitive Services Platform to Azure Marketplace. Beginning October 31st, 2020, provisioning of any new instances of Bing Search APIs will need to be done via Azure Marketplace. All existing instances of Bing Search APIs, provisioned under Azure Cognitive Services, will be supported up to the next three years or till the end of the customer’s enterprise agreement, whichever happens first.” https://blogs.bing.com/search-quality-insights/october-2020/Bing-Search-APIS-are-Transitioning

Microsoft has made some changes on 30 Oct, so the API seems no longer working. So as a workaround, you can use bing-image-downloader as below:

!pip install bing-image-downloader
from bing_image_downloader import downloader

downloader.download("grizzly bear", limit=150, output_dir='bears', adult_filter_off=True, force_replace=False, timeout=5)
downloader.download("black bear", limit=150, output_dir='bears', adult_filter_off=True, force_replace=False, timeout=5)
downloader.download("teddy bear", limit=150, output_dir='bears', adult_filter_off=True, force_replace=False, timeout=5)

path = Path('bears/grizzly bear')
path.rename('bears/grizzly')
path = Path('bears/black bear')
path.rename('bears/black')
path = Path('bears/teddy bear')
path.rename('bears/teddy')
6 Likes

Seems BING did some changes in the result json.
Use contentUrl, for example:

download_images(dest, urls=results.attrgot(‘contentUrl’))

Thanks, very helpful.
Yet I’m running it and most of the images I get in return are not relevant at all. Any Idea what has gone wrong?

I did try to run the search manually, it shows the right photos, but the downloaded images are not, e.g. http://cdn.architecturendesign.net/wp-content/uploads/2014/08/364.jpg