# SearXNG Troubleshooting Guide for Reddit Search

When using self-hosted SearXNG as the backend for Reddit search, you may encounter these issues.

## Common Errors & Fixes

### 1. "Too Many Requests" (HTTP 429)

**Symptom:**
```
HTTP/1.0 429 TOO MANY REQUESTS
```

**Cause:** Rate limiter is enabled in SearXNG configuration (default for public instances).

**Fix:** Disable limiter in settings:
```yaml
server:
  limiter: false  # ← Disable rate limiting
```

Then restart SearXNG:
```bash
pkill -f "searx/webapp.py"
# Start again with updated config
source ~/searxng-venv/bin/activate
export SEARXNG_SETTINGS_PATH=~/searxng-settings/settings.yml
export SEARXNG_PORT=8080
python ~/searxng/searx/webapp.py
```

### 2. "403 Forbidden" on JSON requests

**Symptom:**
```bash
curl "http://127.0.0.1:8080/search?q=test&format=json"
# Returns: <h1>403 Forbidden</h1>
```

**Cause:** JSON format is not enabled in allowed output formats.

**Fix:** Add JSON to formats list in settings:
```yaml
search:
  formats:
    - html
    - json      # ← Required for programmatic access
    - csv       # Optional
    - rss       # Optional
```

Restart SearXNG after changes.

### 3. No Reddit results returned

**Possible causes:**

A. **SearXNG not running**
   ```bash
   # Check if service is running
   ps aux | grep searx
   
   # If not, start it:
   source ~/searxng-venv/bin/activate
   export SEARXNG_SETTINGS_PATH=~/searxng-settings/settings.yml
   export SEARXNG_PORT=8080
   python ~/searxng/searx/webapp.py
   ```

B. **Search engines disabled**
   - Ensure google, brave, startpage engines are enabled in SearXNG config
   - Some engines may be disabled due to CAPTCHAs or rate limits

C. **Wrong SearXNG URL**
   - Script defaults to `http://127.0.0.1:8080`
   - If running on different port/host, update `SEARXNG_URL` in script

### 4. Slow response times

**Solutions:**
- Disable slow engines in SearXNG config
- Reduce `--limit` parameter in search_reddit.py
- Check network connectivity to search engines

## Configuration Checklist

For reliable Reddit search via SearXNG, ensure:

- [ ] `limiter: false` in server section
- [ ] `json` in formats list
- [ ] Multiple engines enabled (google, brave, startpage recommended)
- [ ] SearXNG process running on correct port
- [ ] No firewall blocking SearXNG port (default 8080)
- [ ] Python `requests` module installed: `pip3 install requests`

## Test SearXNG Setup

```bash
# Basic connectivity test
curl http://127.0.0.1:8080/

# JSON API test
curl "http://127.0.0.1:8080/search?q=test&format=json" | python3 -m json.tool

# Reddit search test
curl "http://127.0.0.1:8080/search?q=site:reddit.com+test&format=json" | python3 -m json.tool
```

All should return valid JSON without errors.

## Known Working Configuration (Ubuntu 22.04)

**File:** `~/searxng-settings/settings.yml`
```yaml
use_default_settings: true

general:
  debug: false
  instance_name: "SearXNG"

search:
  safe_search: 2
  autocomplete: 'duckduckgo'
  formats:
    - html
    - json
    - csv
    - rss

server:
  secret_key: "your-secret-key-here"
  limiter: false
  image_proxy: true

valkey:
  url: valkey://localhost:6379/0
```

**Startup command:**
```bash
cd ~
source ~/searxng-venv/bin/activate
export SEARXNG_SETTINGS_PATH=~/searxng-settings/settings.yml
export SEARXNG_PORT=8080
python ~/searxng/searx/webapp.py
```

## Comparison: DuckDuckGo vs SearXNG

| Aspect | DuckDuckGo (v2.x) | SearXNG (v3.x) |
|--------|---------------------|------------------|
| Bot Protection | ❌ Blocks automated requests | ✅ JSON API, no bot issues |
| Rate Limiting | ❌ No official limit | ✅ Self-hosted, configurable |
| Multi-engine | ❌ Single source | ✅ Aggregates Google, Brave, Startpage |
| JSON Output | ❌ HTML parsing required | ✅ Native JSON support |
| Privacy | External service | ✅ Self-hosted, private |
| Setup complexity | Simple | Medium (requires SearXNG instance) |

## Session Notes (2026-04-30)

- User had SearXNG already installed at `/root/searxng` with venv at `/root/searxng-venv`
- Configuration path: `~/searxng-settings/settings.yml`
- Default port: 8080
- Required two config changes: disable limiter + enable json format
- Both issues were blocking Reddit search until resolved
