Downloading images - Book Chapter 2

Hello,

I’m trying to download the images for the grizzly bears in Chapter 2 without success. I’m working through the book and I’m using Colab. My attempts are below.

Can anybody please provide some guidance? I don’t know which folder the images are being saved to…

Much appreciated.

#hide

!pip install -Uqq fastbook

import fastbook

fastbook.setup_book()

#hide

from fastbook import *

from fastai.vision.widgets import *

key = os.environ.get(‘AZURE_SEARCH_KEY’, ‘xxx’)

results = search_images_bing(key, ‘grizzly bear’)

ims = results.attrgot(‘content_url’)

len(ims)

dest = ‘images/grizzly.jpg’

download_url(ims[0], dest)

im = Image.open(dest)

im.to_thumb(128,128)

MissingSchema Traceback (most recent call last)
in ()
1 dest = ‘images/grizzly.jpg’
----> 2 download_url(ims[0], dest)
3
4 im = Image.open(dest)
5 im.to_thumb(128,128)

5 frames
/usr/local/lib/python3.6/dist-packages/requests/models.py in prepare_url(self, url, params)
386 error = error.format(to_native_string(url, ‘utf8’))
387
–> 388 raise MissingSchema(error)
389
390 if not host:

MissingSchema: Invalid URL ‘None’: No schema supplied. Perhaps you meant http://None?

TLDR:

change:
ims = results.attrgot(‘content_url’)

to:
ims = results.attrgot(‘contentUrl’)

The book and repo both have an error in this line:

ims = results.attrgot(‘content_url’)

If you print the results, you can see that the Bing Search API uses the variable “contentUrl” not “content_url”:

‘contentUrl’: ‘images.gearjunkie.com/uploads/2015/07/Grizzly-Bear.jpg’,

So the referenced line needs to be changed to:

ims = results.attrgot(‘contentUrl’)

There is an additional certificate error bug in some environments that prevents this from running that appears to have been closed:

According to the report, it’s been resolved for Paperspace instances, but it’s still broken in Google Colab. You’ll probably need to switch to Paperspace to keep working through book.

2 Likes

Thanks Poodleman. Yes, I was having some teething issues with using Colab. I haven’t used Paperspace yet but will look into it if that is slicker with the FastAI API.

Much appreciated.

Hi there
I am getting this same error right now.
I tried changing the code as per the reply above, but to no avail. Please help.

Thank you so much in advance. Much appreciated.