diff --git a/desearch/tools/search/serp_api_wrapper.py b/desearch/tools/search/serp_api_wrapper.py index 0e9351ad..43ee2b11 100644 --- a/desearch/tools/search/serp_api_wrapper.py +++ b/desearch/tools/search/serp_api_wrapper.py @@ -1,4 +1,5 @@ import aiohttp +from aiohttp import ClientTimeout from typing import Any, Dict, Optional, Tuple @@ -37,12 +38,13 @@ def construct_url_and_params() -> Tuple[str, Dict[str, str]]: return url, params url, params = construct_url_and_params() + timeout = ClientTimeout(total=30) if not self.aiosession: - async with aiohttp.ClientSession() as session: - async with session.get(url, params=params) as response: + async with aiohttp.ClientSession(timeout=timeout) as session: + async with session.get(url, params=params, timeout=timeout) as response: res = await response.json() else: - async with self.aiosession.get(url, params=params) as response: + async with self.aiosession.get(url, params=params, timeout=timeout) as response: res = await response.json() return res