fastai / course22-web

Website for Practical Deep Learning for Coders 2022
https://course.fast.ai
Apache License 2.0
43 stars 24 forks source link

Chapter 1 Notebook: search_images throws HTTPStatusError: Client error '403 Forbidden' #34

Open ChrisTho23 opened 2 months ago

ChrisTho23 commented 2 months ago

The search_images function in the first notebook does not work neither for me nor many other users (see notebook comments). I tracked this down to an issue with the duckduckgo_search library. According to this (thread)[https://github.com/deedy5/duckduckgo_search/issues/136], the following code solves the problem. I tried it out and indeed, I can run the notebook without any problems.

from duckduckgo_search import DDGS
from fastcore.foundation import L

def search_images(term, max_images=30):
    print(f"Searching for '{term}'")
    with DDGS(headers = {"Accept-Encoding": "gzip, deflate, br"}) as ddgs:
        results = ddgs.images(keywords=term)
        return L(results).itemgot('image')