diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 4c4bdab..f2facba 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,27 +1,23 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- **Before you open an issue:** -1. Make sure you have the latest version installed. Check: `ddgs version`. Update: `pip install -U duckduckgo_search` -3. Try reinstalling the library: `pip install -I duckduckgo_search` -4. Make sure the site https://duckduckgo.com is accessible in your browser -5. Try using a proxy. The site may block ip for a while. +- [ ] I have the latest version. (Check: `ddgs version`. Update: `pip install -U duckduckgo_search`)
+- [ ] I tried reinstalling the library. (`pip install -I duckduckgo_search`) +- [ ] https://duckduckgo.com is accessible in my browser +- [ ] I tried using a proxy (the site may block ip for a while) + +## Describe the bug -**Describe the bug** What the bug is. **Debug log** + Add `logging.basicConfig(level=logging.DEBUG)` to the beginning of your script and attach log to the issue. **Screenshots** + If applicable, add screenshots to help explain your problem. **Specify this information** + - OS - environment - duckduckgo_search version diff --git a/README.md b/README.md index 0cb2106..7448d3b 100755 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Search for words, documents, images, videos, news, maps and text translation usi * [Duckduckgo search operators](#duckduckgo-search-operators) * [Regions](#regions) * [DDGS and AsyncDDGS classes](#ddgs-and-asyncddgs-classes) -* [Using proxy](#using-proxy) +* [Proxies](#proxies) * [Exceptions](#exceptions) * [1. text() - text search](#1-text---text-search-by-duckduckgocom) * [2. answers() - instant answers](#2-answers---instant-answers-by-duckduckgocom) @@ -183,8 +183,13 @@ with DDGS() as ddgs: Here is an example of initializing the AsyncDDGS class: ```python3 import asyncio +import sys from duckduckgo_search import AsyncDDGS +# bypass curl-cffi NotImplementedError in windows https://curl-cffi.readthedocs.io/en/latest/faq/ +if sys.platform.lower().startswith("win"): + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + async def get_results(): async with AsyncDDGS() as ddgs: results = [r async for r in ddgs.text("cat", max_results=5)] @@ -202,7 +207,13 @@ This ensures proper resource management and cleanup, as the context manager will [Go To TOP](#TOP) -## Using proxy +## Proxies +Proxy can be specified as a dictionary or just a string +```python +proxies = {"http": "socks5://localhost:9150", "https": "socks5://localhost:9150"} +proxies = "socks5://localhost:9150" +``` + *1. The easiest way. Launch the Tor Browser* ```python3 from duckduckgo_search import DDGS diff --git a/duckduckgo_search/duckduckgo_search.py b/duckduckgo_search/duckduckgo_search.py index e5eabc4..ace526f 100644 --- a/duckduckgo_search/duckduckgo_search.py +++ b/duckduckgo_search/duckduckgo_search.py @@ -43,7 +43,7 @@ def _get_url(self, method: str, url: str, **kwargs) -> Optional[requests.Respons logger.debug(f"_get_url() {url} {resp.status_code} {resp.http_version} {resp.elapsed} {len(resp.content)}") resp.raise_for_status() if _is_500_in_url(str(resp.url)) or resp.status_code == 202: - raise + raise DuckDuckGoSearchException("Ratelimit") if resp.status_code == 200: return resp except Exception as ex: diff --git a/duckduckgo_search/duckduckgo_search_async.py b/duckduckgo_search/duckduckgo_search_async.py index c763962..8fbfa31 100644 --- a/duckduckgo_search/duckduckgo_search_async.py +++ b/duckduckgo_search/duckduckgo_search_async.py @@ -48,7 +48,7 @@ async def _get_url(self, method: str, url: str, **kwargs) -> Optional[requests.R logger.debug(f"_get_url() {url} {resp.status_code} {resp.http_version} {resp.elapsed} {len(resp.content)}") resp.raise_for_status() if _is_500_in_url(str(resp.url)) or resp.status_code == 202: - raise + raise DuckDuckGoSearchException("Ratelimit") if resp.status_code == 200: return resp except Exception as ex: diff --git a/duckduckgo_search/version.py b/duckduckgo_search/version.py index 7039708..72aa758 100755 --- a/duckduckgo_search/version.py +++ b/duckduckgo_search/version.py @@ -1 +1 @@ -__version__ = "4.1.0" +__version__ = "4.1.1"