Lesson 02: download_images() function not working

At the following cell, I get an error at the download_images() line.

if not path.exists():
for o in bear_types:
dest = (path/o)
results = search_images_bing(key, f’{o} bear’)
download_images(dest, urls=results.attrgot(‘content_url’))

The error is as the following. Any idea why the download_images() function is not working?

_RemoteTraceback Traceback (most recent call last)
Traceback (most recent call last):
File “/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/process.py”, line 239, in _process_worker
r = call_item.fn(*call_item.args, **call_item.kwargs)
File “/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/process.py”, line 198, in _process_chunk
return [fn(*args) for args in chunk]
File “/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/process.py”, line 198, in
return [fn(*args) for args in chunk]
File “/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/xtras.py”, line 475, in _call
return g(item)
File “/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/vision/utils.py”, line 25, in _download_image_inner
url_path = Path(url)
File “/opt/conda/envs/fastai/lib/python3.8/pathlib.py”, line 1038, in new
self = cls._from_parts(args, init=False)
File “/opt/conda/envs/fastai/lib/python3.8/pathlib.py”, line 679, in _from_parts
drv, root, parts = self._parse_args(args)
File “/opt/conda/envs/fastai/lib/python3.8/pathlib.py”, line 663, in _parse_args
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
5 dest.mkdir(exist_ok=True)
6 results = search_images_bing(key, f’{o} bear’)
----> 7 download_images(dest, urls=results.attrgot(‘content_url’))

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/vision/utils.py in download_images(dest, url_file, urls, max_pics, n_workers, timeout, preserve_filename)
35 dest = Path(dest)
36 dest.mkdir(exist_ok=True)
—> 37 parallel(partial(_download_image_inner, dest, timeout=timeout, preserve_filename=preserve_filename),
38 list(enumerate(urls)), n_workers=n_workers)


I just fixed the above issue with

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

instead of

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

Maybe this could help someone else.


FYI that’s fixed in the latest version of the fastbook repo. It’s a change in the underlying Bing API.

1 Like

Where do I find this latest repository? (I am using Papersace Gradient and I have access to the same repo that I had about 2 weeks ago when I created an account. Should I update this? How?)
Thanks. (I’m still an absolute beginner at this)

Just so people running this in a local notebook in Visual Studio Code know, this works. Using the ‘_’ causes ims to be [ none, none…none], with the correction by robocup, you’ll get the URLs of the images.

I was having this issue with the latest notebook on 02.production.ipynb
, the fix for me was to change it back to ‘content_url’

download_images(dest, urls=results.attrgot('content_url')) works