iflytek/astron-agent · error · AssembleHeaderException

invalid request url

Error message

invalid request url:{requset_url}

What it means

parse_url in the link plugin's WebSocket auth helper raises AssembleHeaderException when the URL has no path component at all: host.index("/") throws ValueError because there is no '/' after the scheme. The function expects a full URL like 'wss://host/path'; a bare 'wss://host' cannot be split into host and path for HMAC header assembly.

Solutions

  1. Append the required API path to the URL, e.g. 'wss://host/v2/interact' instead of 'wss://host'
  2. Check the service's endpoint configuration/env var for the full URL including path
  3. Catch AssembleHeaderException and log/validate the URL before calling assemble_ws_auth_url

Example fix

# before
url = "wss://iat-api.xfyun.cn"
result_url, headers = assemble_ws_auth_url(url, "GET", auth_config)  # raises
# after
url = "wss://iat-api.xfyun.cn/v2/iat"
result_url, headers = assemble_ws_auth_url(url, "GET", auth_config)
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse

def assert_parseable_ws_url(url: str) -> None:
    p = urlparse(url)
    if p.scheme not in ("ws", "wss") or not p.hostname or not p.path:
        raise ValueError(f"URL must include scheme, host and path: {url}")

Try / catch

try:
    result_url, headers = assemble_ws_auth_url(url, "GET", auth_config)
except AssembleHeaderException as e:
    logger.error(f"bad endpoint url: {e.message}")
    raise ValueError("endpoint URL must include a path") from e

Prevention

When it happens

Trigger: Passing assemble_ws_auth_url (via parse_url) a URL without any path, e.g. 'wss://apiserver.example.com' instead of 'wss://apiserver.example.com/v2/interact' — typically a misconfigured endpoint base URL stored in config or env.

Common situations: Configuring only the host of an upstream WebSocket API without its required route, copying an API domain from docs without the endpoint path, or stripping the path in URL-joining code.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/8037ed6d5dd517a7. Report an issue: GitHub.

Appendix: source

Thrown at core/plugin/link/infra/tool_exector/http_auth.py:153

    """
    Parse a URL into its components.

    Args:
        requset_url (str): The URL to parse

    Returns:
        Url: A Url object containing host, path, and schema components

    Raises:
        AssembleHeaderException: If the URL format is invalid
    """
    stidx = requset_url.index("://")
    host = requset_url[stidx + 3 :]
    schema = requset_url[: stidx + 3]
    try:
        edidx = host.index("/")
    except ValueError:
        raise AssembleHeaderException("invalid request url:" + requset_url)
    if edidx <= 0:
        raise AssembleHeaderException("invalid request url:" + requset_url)
    path = host[edidx:]
    host = host[:edidx]
    u = Url(host, path, schema)
    return u


# build websocket auth request url
def assemble_ws_auth_url(
    requset_url: str,
    method: str,
    auth_con_js: Dict[str, Any],
    body: Optional[Dict[str, Any]] = None,
) -> Tuple[str, Dict[str, str]]:
    """
    Build WebSocket authentication request URL and headers.

View on GitHub (pinned to 5e758547a8)