course22-web icon indicating copy to clipboard operation
course22-web copied to clipboard

persistent HTTPError from search_images('bird photos')

Open mayerber opened this issue 2 years ago • 5 comments

I'm running the Is it a bird? notebook (first class) and getting HTTPError when searching bird photos in Step 1: Download images of birds and non-birds. The cell recommends retrying upon a JSON error, though retries are not helping for the past couple days. Traceback follows:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
/tmp/ipykernel_17/2432147335.py in <module>
      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:

mayerber avatar Nov 29 '23 11:11 mayerber

I'm getting the same issue. Always errors.

hikeeba avatar Nov 30 '23 19:11 hikeeba

Just tried this again and adjusted the notebook environment setting to Always use latest environment instead of Pin to original environment (2022-03-17) and it seems to be working with that change.

hikeeba avatar Dec 06 '23 17:12 hikeeba

image

hikeeba avatar Dec 06 '23 17:12 hikeeba

Just tried this again and adjusted the notebook environment setting to Always use latest environment instead of Pin to original environment (2022-03-17) and it seems to be working with that change.

Thanks, this helped!

pranavhonrao9 avatar Dec 08 '23 05:12 pranavhonrao9

Also getting this; and the latest env makes it break on ddg images.

Removing the ddg lib, and adding this fix for broken code fixed it for me.

ukd1 avatar Feb 01 '24 18:02 ukd1