calesthio/OpenMontage · error · RuntimeError

Non-JSON response from DashScope API: HTTP {response.status_

Error message

Non-JSON response from DashScope API: HTTP {response.status_code}

What it means

Raised by _json_or_raise when a DashScope HTTP response body cannot be parsed as JSON (requests raises ValueError from response.json()). This usually means the endpoint returned HTML (auth wall, proxy error page) or an empty body instead of the expected JSON envelope. The RuntimeError wraps the original ValueError with the HTTP status for context.

Source

Thrown at tools/analysis/dashscope_asr.py:365

                    words.append(
                        {
                            "text": word.get("text", ""),
                            "begin_time_seconds": round(
                                word.get("begin_time", 0) / 1000.0, 3
                            ),
                            "end_time_seconds": round(
                                word.get("end_time", 0) / 1000.0, 3
                            ),
                        }
                    )
        return words

    @staticmethod
    def _json_or_raise(response: Any) -> dict[str, Any]:
        try:
            return response.json()
        except ValueError as exc:
            raise RuntimeError(
                f"Non-JSON response from DashScope API: "
                f"HTTP {response.status_code}"
            ) from exc

    def _raise_for_error(
        self, http_status: int, payload: dict[str, Any]
    ) -> None:
        if http_status < 400:
            return
        code = payload.get("code")
        message = payload.get("message", "unknown error")
        raise RuntimeError(
            f"DashScope API error: HTTP {http_status}, "
            f"code {code}: {message}"
        )

    @staticmethod
    def _safe_error(exc: Exception) -> str:

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. Print/log response.status_code and response.text[:500] at the raise site to see what actually came back
  2. Check proxy env vars (HTTP_PROXY/HTTPS_PROXY/NO_PROXY) and bypass them for dashscope.aliyuncs.com
  3. Verify the base URL configuration and that DASHSCOPE_API_KEY is set and valid
  4. Retry once — transient 502/503 HTML pages from gateways often clear immediately

Example fix

// before
data = self._json_or_raise(resp)

// after — capture diagnostics before the generic raise
try:
    data = self._json_or_raise(resp)
except RuntimeError:
    logger.error("body=%r status=%s", resp.text[:500], resp.status_code)
    raise
Defensive patterns

Strategy: retry

Type guard

def is_json_response(resp) -> bool:
    content_type = resp.headers.get("Content-Type", "")
    return "application/json" in content_type

Try / catch

try:
    data = self._json_or_raise(resp)
except RuntimeError as e:
    if "Non-JSON" in str(e):
        logger.error("dashscope non-JSON body: %r (status %s)", resp.text[:500], resp.status_code)
        # one retry — gateway HTML pages are often transient
        resp = session.post(url, json=payload, timeout=timeout)
        data = self._json_or_raise(resp)
    else:
        raise

Prevention

When it happens

Trigger: requests.post/get to the DashScope REST endpoint returning HTML from a corporate proxy, a CAPTCHA/anti-bot page, or a 502 gateway error with an HTML body; an empty body from a truncated connection; hitting the wrong base URL (typo, environment override) that serves a generic web page.

Common situations: HTTP_PROXY/HTTPS_PROXY env vars routing DashScope traffic through a proxy that injects error pages; DNS or region misconfiguration pointing at a non-API host; intermittent gateway errors on Aliyun edge nodes; the API key missing causing a redirect to a login page.

Related errors


AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15). Data as JSON: /api/errors/f5f205b6308cf45d. Report an issue: GitHub.