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
This commit is contained in:
@@ -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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user