Closed adhadse closed 3 months ago
Your code doesn't work
Use asyncio.Semaphore to limit the number of concurrent requests. Increase timeout. Correct 'timelimit'.
import asyncio
import logging
from duckduckgo_search import AsyncDDGS
logging.basicConfig(level=logging.DEBUG)
SEM = asyncio.Semaphore(10)
proxies = "socks5://localhost:9150"
async def aget_results(keywords):
async with SEM:
while True:
try:
results = await AsyncDDGS(proxies=proxies, timeout=20).news(
keywords,
region="wt-wt",
safesearch="off",
timelimit="d",
max_results=20,
)
return results
except Exception as ex:
logging.warning(f"{type(ex).__name__}: {ex}")
async def main():
words = ["sun", "earth", "moon"]
tasks = [aget_results(keywords=w) for w in words]
results = await asyncio.gather(*tasks)
for r in results:
print(r)
print(len(r))
return results
if __name__ == "__main__":
asyncio.run(main())
Hey there.
I'm facing an issue running AsyncDDGS with proxy (http endpoint). Even after multiple retries, there are multiple search failing and only few returning results.
Most prominently I receieved were:
RequestsError: Failed to perform, curl: (28) Proxy CONNECT aborted due to timeout.
SSL connection timeout
Could it be that there are too many connection being made via the Async code and so multiple connections are failing via proxy?
Code:
What could be the problem, if the number of connections is the problem how can I control it. I do remember semaphores exist but how to use it here?