{"record":{"id":"ec09a6baa1de4854","repo":"Fosowl/agenticSeek","slug":"searxng-base-url-must-be-provided-either-as-an-arg","errorCode":null,"errorMessage":"SearxNG base URL must be provided either as an argument or via the SEARXNG_BASE_URL environment variable.","messagePattern":"SearxNG base URL must be provided either as an argument or via the SEARXNG_BASE_URL environment variable\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sources/tools/searxSearch.py","lineNumber":27,"sourceCode":"\nfrom sources.tools.tools import Tools\n\nclass searxSearch(Tools):\n    def __init__(self, base_url: str = None):\n        \"\"\"\n        A tool for searching a SearxNG instance and extracting URLs and titles.\n        \"\"\"\n        super().__init__()\n        self.tag = \"web_search\"\n        self.name = \"searxSearch\"\n        self.description = \"A tool for searching a SearxNG for web search\"\n        self.base_url = base_url or os.getenv(\"SEARXNG_BASE_URL\")  # Requires a SearxNG base URL\n        self.user_agent = \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36\"\n        self.paywall_keywords = [\n            \"Member-only\", \"access denied\", \"restricted content\", \"404\", \"this page is not working\"\n        ]\n        if not self.base_url:\n            raise ValueError(\"SearxNG base URL must be provided either as an argument or via the SEARXNG_BASE_URL environment variable.\")\n\n    def link_valid(self, link):\n        \"\"\"check if a link is valid.\"\"\"\n        # TODO find a better way\n        if not link.startswith(\"http\"):\n            return \"Status: Invalid URL\"\n        \n        headers = {\"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\"}\n        try:\n            response = requests.get(link, headers=headers, timeout=5)\n            status = response.status_code\n            if status == 200:\n                content = response.text.lower()\n                if any(keyword in content for keyword in self.paywall_keywords):\n                    return \"Status: Possible Paywall\"\n                return \"Status: OK\"\n            elif status == 404:\n                return \"Status: 404 Not Found\"","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/tools/searxSearch.py#L9-L45","documentation":"The SearxSearch tool's __init__ requires a SearxNG instance URL, taken from the base_url argument or the SEARXNG_BASE_URL environment variable. If both are missing it raises ValueError immediately at construction time, because the tool cannot function without a SearxNG endpoint.","triggerScenarios":"Instantiating SearxSearch() (or whatever wraps it) with no base_url argument while SEARXNG_BASE_URL is unset in the environment — the `if not self.base_url` check at searxSearch.py:27 fires.","commonSituations":"Fresh checkout where .env was never created or not loaded (load_dotenv not called before construction); SEARXNG_BASE_URL defined in one shell but the app runs in another; typo'd env var name; self-hosted SearxNG not reachable so the URL was never configured.","solutions":["Set the env var: export SEARXNG_BASE_URL=https://your-searxng-instance (and ensure .env is loaded before constructing the tool)","Pass base_url explicitly: SearxSearch(base_url='https://searx.example.com')","Verify the variable name spelling and that it is visible to the process (print os.getenv in the same interpreter)","Stand up or reach a SearxNG instance (public instance or docker run searxng) if you have none"],"exampleFix":"// before\nsearch = SearxSearch()  # ValueError: no base URL\n// after\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nassert os.getenv('SEARXNG_BASE_URL'), 'Set SEARXNG_BASE_URL'\nsearch = SearxSearch()","handlingStrategy":"validation","validationCode":"import os\nfrom dotenv import load_dotenv\nload_dotenv()\nif not (os.getenv('SEARXNG_BASE_URL') or '').startswith('http'):\n    raise SystemExit('Set SEARXNG_BASE_URL (e.g. https://searx.example.com) before constructing SearxSearch')","typeGuard":null,"tryCatchPattern":"try:\n    search = SearxSearch()\nexcept ValueError as e:\n    logger.error('SearxNG not configured: %s', e)\n    raise SystemExit('Provide base_url or SEARXNG_BASE_URL env var') from e","preventionTips":["Add SEARXNG_BASE_URL to .env and load it before tool construction","Construct search tools in a startup step that fails fast with a clear config check","Validate the URL with a health ping (/search?q=test) at boot","Keep env var names consistent across deployment scripts and containers"],"tags":["missing-env-var","configuration","searxng","valueerror"],"backgroundTag":"missing-env-var","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}