Lesson 1 official topic

This error crops up because the API for the duckduckgo-search library has changed slightly since the notebook was originally published.

A couple of ways to get the notebook working:
(1) Replace ddg_images with search_images_ddg from the fastbook library. This is the quickest way to get it going. The fix with a code example is originally mentioned here: Lesson 1 official topic - #608 by SergeyF
(2) Rewrite the search_images function using the updated DDGS class. Example:

from duckduckgo_search import DDGS

def search_img_urls(keywords: str, max_results: int) -> list:
    """
    Searches DDG using the keywords string and returns a list of 
    matching image urls up to length max_results.
    """
    with DDGS() as ddgs:
        keywords = keywords
        ddgs_images_gen = ddgs.images(
            keywords,
            max_results=max_results
        )
        r = [result["image"] for result in ddgs_images_gen]
    return r
4 Likes