deedy5 / duckduckgo_search

Search for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. Downloading files and images to a local hard drive.
MIT License
932 stars 117 forks source link

HTTPError using ddgs.text() #110

Closed tybantarnusa closed 10 months ago

tybantarnusa commented 10 months ago

Describe the bug

I got this generic HTTPError using text() following exactly the code like in the example here.

Traceback (most recent call last):
  File "E:\Projects\test.py", line 5, in <module>
    for r in ddgs.text(1, region='wt-wt', safesearch='Off', timelimit='y'):
  File "E:\Projects\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 150, in text
    yield from self._text_api(keywords, region, safesearch, timelimit)
  File "E:\Projects\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 203, in _text_api
    resp = self._get_url(
           ^^^^^^^^^^^^^^
  File "E:\Projects\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 89, in _get_url
    raise ex
  File "E:\Projects\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 82, in _get_url
    raise httpx._exceptions.HTTPError("")
httpx.HTTPError

This is the code:

from duckduckgo_search import DDGS

q = input('Search: ')
with DDGS() as ddgs:
    for r in ddgs.text(q, region='wt-wt', safesearch='Off', timelimit='y'):
        print(r)

Information

deedy5 commented 10 months ago

The error occurs because the parameter safesearch='Off' is capitalized, you need safesearch='off'.

There was an error in the Readme. Please correct it to be like this:

from duckduckgo_search import DDGS

q = input('Search: ')
with DDGS() as ddgs:
    for r in ddgs.text(q, region='wt-wt', safesearch='off', timelimit='y', backend='lite'):
        print(r)