Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistent HTTPError from search_images('bird photos') #15

Open
mayerber opened this issue Nov 29, 2023 · 5 comments
Open

persistent HTTPError from search_images('bird photos') #15

mayerber opened this issue Nov 29, 2023 · 5 comments

Comments

@mayerber
Copy link

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:
@hikeeba
Copy link

hikeeba commented Nov 30, 2023

I'm getting the same issue. Always errors.

@hikeeba
Copy link

hikeeba commented Dec 6, 2023

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
Copy link

hikeeba commented Dec 6, 2023

image

@pranavhonrao9
Copy link

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!

@ukd1
Copy link

ukd1 commented Feb 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants