binary-husky/gpt_academic · error · ValueError

在线搜索失败,状态码: {response.status_code}\t{response.content.decode

Error message

在线搜索失败,状态码: {response.status_code}\t{response.content.decode('utf-8')}

What it means

searxng_request() received a non-200, non-429 HTTP response and converts the status plus UTF-8 body into ValueError. This is the generic SearxNG transport/configuration failure path.

Source

Thrown at crazy_functions/Internet_GPT.py:166

    }
    results = []
    response = requests.post(url, params=params, headers=headers, proxies=proxies, timeout=30)
    if response.status_code == 200:
        json_result = response.json()
        for result in json_result['results']:
            item = {
                "title": result.get("title", ""),
                "source": result.get("engines", "unknown"),
                "content": result.get("content", ""),
                "link": result["url"],
            }
            results.append(item)
        return results
    else:
        if response.status_code == 429:
            raise ValueError("Searxng(在线搜索服务)当前使用人数太多,请稍后。")
        else:
            raise ValueError("在线搜索失败,状态码: " + str(response.status_code) + '\t' + response.content.decode('utf-8'))


def scrape_text(url, proxies) -> str:
    """Scrape text from a webpage

    Args:
        url (str): The URL to scrape text from

    Returns:
        str: The scraped text
    """
    from loguru import logger
    headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36',
        'Content-Type': 'text/plain',
    }

    # 首先采用Jina进行文本提取

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Run the same query against the configured URL with curl and format=json to see the raw status/body.
  2. Correct SEARXNG_URLS and confirm the instance allows JSON responses.
  3. Enable the requested engines/categories on the SearxNG server.
  4. Check proxy connectivity and remove headers that the instance rejects.
  5. Treat 5xx as transient with a retry and a fallback URL.

Example fix

# before
raise ValueError("在线搜索失败,状态码: " + str(response.status_code) + '\t' + response.content.decode('utf-8'))

# after
body = response.content.decode("utf-8", errors="replace")
raise ValueError(
    f"在线搜索失败,状态码: {response.status_code}; url={response.url}; body={body[:500]}"
)
Defensive patterns

Strategy: validation

Validate before calling

urls = get_conf("SEARXNG_URLS")
for base in urls:
    probe = requests.post(base, params={"q": "test", "format": "json"}, timeout=5)
    if probe.status_code == 200 and probe.headers.get("content-type", "").startswith("application/json"):
        break
else:
    raise RuntimeError("No SearxNG URL returns JSON")

Type guard

def is_json_searxng_response(response) -> bool:
    return (
        response.status_code == 200
        and response.headers.get("content-type", "").startswith("application/json")
        and isinstance(response.json().get("results"), list)
    )

Try / catch

try:
    results = searxng_request(...)
except ValueError as e:
    log_searxng_status_and_body(e)
    raise

Prevention

When it happens

Trigger: HTTP 403 when JSON output or API access is disabled, 404 for a wrong URL/path, 400 for unsupported parameters, 500/502 for engine/server failure, or any other provider error status.

Common situations: SEARXNG_URLS points to the base site instead of the search endpoint or an old instance; SearXNG's search.formats does not include json; a proxy modifies or blocks the request; engines/categories are not available on that instance; the service is down.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/dd781af7bf9d03fa. Report an issue: GitHub.