From a976afdbd77ce83d3dd3cff114a2e89e0ff66575 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Fri, 10 Apr 2026 10:07:06 +0800 Subject: [PATCH] fix: URL-encode search query and detect empty results as failure (fixes #274) - Use urllib.parse.urlencode to properly encode the POST body, so queries containing special characters like '&', '+', '=' are sent correctly - Extend execution_failure_check to also detect "No search results" as a failure, preventing the agent from silently looping when all SearXNG engines are rate-limited and return no results --- sources/tools/searxSearch.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sources/tools/searxSearch.py b/sources/tools/searxSearch.py index 686d3e1..418e6c4 100644 --- a/sources/tools/searxSearch.py +++ b/sources/tools/searxSearch.py @@ -1,6 +1,7 @@ import requests from bs4 import BeautifulSoup import os +from urllib.parse import urlencode if __name__ == "__main__": # if running as a script for individual testing sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) @@ -77,7 +78,14 @@ class searxSearch(Tools): 'Upgrade-Insecure-Requests': '1', 'User-Agent': self.user_agent } - data = f"q={query}&categories=general&language=auto&time_range=&safesearch=0&theme=simple".encode('utf-8') + data = urlencode({ + 'q': query, + 'categories': 'general', + 'language': 'auto', + 'time_range': '', + 'safesearch': '0', + 'theme': 'simple' + }).encode('utf-8') try: response = requests.post(search_url, headers=headers, data=data, verify=False) response.raise_for_status() @@ -101,7 +109,7 @@ class searxSearch(Tools): """ Checks if the execution failed based on the output. """ - return "Error" in output + return "Error" in output or "No search results" in output def interpreter_feedback(self, output: str) -> str: """