Beginner Setup

I just started the training. I edited and copied the Kaggle notebook and ran the cells accordingly. The Internet is turned on. I continued to get errors after running the cell, as shown below. I ran this time without a number.

  1. Please, how do I resolve this?
  2. I thought I would be able to follow along, running the cells as is in the kaggle jupyter notebook
  3. Do I need to set up a different environment?

Please, this is not allowing me to progress, as I do not want to just watch the video but follow along.

Cell
#NB: search_images depends on duckduckgo.com, which doesn’t always return correct responses.

If you get a JSON error, just try running it again (it may take a couple of tries).

urls = search_images(‘bird photos’, max_images=1)
urls[0]

Error

HTTPError Traceback (most recent call last)
/tmp/ipykernel_17/2432147335.py in
1 #NB: search_images depends on duckduckgo.com, which doesn’t always return correct responses.
2 # If you get a JSON error, just try running it again (it may take a couple of tries).
----> 3 urls = search_images(‘bird photos’, max_images=1)
4 urls[0]

/tmp/ipykernel_17/1717929076.py in search_images(term, max_images)
4 def search_images(term, max_images=30):
5 print(f"Searching for ‘{term}’")
----> 6 return L(ddg_images(term, max_results=max_images)).itemgot(‘image’)

/opt/conda/lib/python3.7/site-packages/duckduckgo_search/compat.py in ddg_images(keywords, region, safesearch, time, size, color, type_image, layout, license_image, max_results, page, output, download)
80 type_image=type_image,
81 layout=layout,
—> 82 license_image=license_image,
83 ):
84 results.append(r)

/opt/conda/lib/python3.7/site-packages/duckduckgo_search/duckduckgo_search.py in images(self, keywords, region, safesearch, timelimit, size, color, type_image, layout, license_image)
403 assert keywords, “keywords is mandatory”
404
→ 405 vqd = self._get_vqd(keywords)
406 assert vqd, “error in getting vqd”
407

/opt/conda/lib/python3.7/site-packages/duckduckgo_search/duckduckgo_search.py in _get_vqd(self, keywords)
93 def _get_vqd(self, keywords: str) → Optional[str]:
94 “”“Get vqd value for a search query.”“”
—> 95 resp = self._get_url(“POST”, “https://duckduckgo.com”, data={“q”: keywords})
96 if resp:
97 for c1, c2 in (

/opt/conda/lib/python3.7/site-packages/duckduckgo_search/duckduckgo_search.py in _get_url(self, method, url, **kwargs)
87 logger.warning(f"_get_url() {url} {type(ex).name} {ex}")
88 if i >= 2 or “418” in str(ex):
—> 89 raise ex
90 sleep(3)
91 return None

/opt/conda/lib/python3.7/site-packages/duckduckgo_search/duckduckgo_search.py in _get_url(self, method, url, **kwargs)
80 )
81 if self._is_500_in_url(str(resp.url)) or resp.status_code == 202:
—> 82 raise httpx._exceptions.HTTPError(“”)
83 resp.raise_for_status()
84 if resp.status_code == 200:

HTTPError:

1 Like

The duckduckgo API has changed since the course was released. Here are a couple of solutions from forum posts that you can try, which replace the code for search_images:

1 Like

Hi, is going through part 1 and part 2 of the still the right way to start learning ml/ai? just checking as we’re entering 2024, and so much has happened in ml/ai lately

Thank you very much @vbakshi, the below code solved my problem

def search_images(term, max_images=200):
    with DDGS(headers = {"Accept-Encoding": "gzip, deflate, br"}) as ddgs:
        results = ddgs.images(keywords=term)
        images = [next(results).get("image") for _ in range(max_images)]
        return L(images)```
2 Likes