fastai / course22

The fast.ai course notebooks
https://course.fast.ai
2.39k stars 934 forks source link

error while searching with duckduckgo_search #84

Open adilsonsc opened 1 year ago

adilsonsc commented 1 year ago

Hi, I'm just beggining the course and I had an issue with the first notebook (Is it a bird?).

When I try run the code, the attempt to make a search with the function search_images returns the following exception:

HTTPError: 403 Client Error: Forbidden for url: https://duckduckgo.com/i.js?l=wt-wt&o=json&s=0&q=bird+photos&vqd=4-117789140384711387116571556492091898243&f=%2C%2C%2C%2C%2C&p=1

I tried to understand the problem and find solution in the forum, but nothing helped.

Please, can you help me?

poltak commented 1 year ago

I had this problem too, but managed to solve it after finding this post from the forums: https://forums.fast.ai/t/duckduckgo-search-not-working/105738/18

It replaces the duckduckgo_search package usage with the function search_images_ddg from fastbook package, which provides the same behavior.

Basically I had to change the pip install -Uqq fastai duckduckgo_search to pip install -Uqq fastai fastbook, to ensure fastbook package is installed. Then in the search_images code block replace the duckduckgo_search usage:

from fastbook import *
from fastcore.all import *

def search_images(term, max_images=30):
    print(f"Searching for '{term}'")
    return search_images_ddg(term, max_images)

It was a bit of a jarring start to the course with the first lesson not working. If this is viewed as an accepted workaround I'd submit a PR

deedy5 commented 1 year ago

just update the package: pip install -U duckduckgo_search

poltak commented 1 year ago

@deedy5 the update flag's in the original command (pip install -Uqq fastai duckduckgo_search), but it didn't work for us

deedy5 commented 1 year ago

I updated search_images() to match the latest version of duckduckgo_search and checked on google collab - everything is fine. PR #85

from itertools import islice
from duckduckgo_search import DDGS
from fastcore.all import *

def search_images(term, max_images=200): 
    with DDGS() as ddgs:
        return [x['image'] for x in islice(ddgs.images(term), max_images)]
poltak commented 1 year ago

Alright, that solution does work for me on Kaggle too :)