Merge pull request #467 from octo-patch/fix/issue-274-searxsearch-query-encoding
fix: URL-encode search query and detect empty results as failure
This commit is contained in:
@@ -2,6 +2,7 @@ import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import sys
|
||||
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__)))))
|
||||
@@ -78,7 +79,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()
|
||||
@@ -102,7 +110,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