iflytek/astron-agent · error · RemoteResourcePolicyError

Remote resource URL port is invalid

Error message

Remote resource URL port is invalid

What it means

RemoteResourcePolicyError raised when the URL specifies a port outside the valid 1-65535 range. Note that urlsplit().port itself raises on out-of-range/undecodable ports; this explicit check in _validate_parsed_resource_url is a defense-in-depth guard for the parsed port value reaching the validator with an invalid value.

Solutions

  1. Fix the URL to use a valid port (1-65535) or omit the port to use the scheme default (80/443)
  2. Check the code/config that generates the port; ensure missing ports default to scheme defaults instead of 0
  3. Validate the port with 1 <= port <= 65535 before building the URL

Example fix

// before
port = int(os.getenv("DOWNLOAD_PORT", "0"))
url = f"https://cdn.example.com:{port}/file"
// after
port = int(os.getenv("DOWNLOAD_PORT", "443"))
if not 1 <= port <= 65535:
    raise ValueError(f"invalid port {port}")
url = f"https://cdn.example.com:{port}/file" if port != 443 else "https://cdn.example.com/file"
Defensive patterns

Strategy: validation

Validate before calling

def has_valid_port(url: str) -> bool:
    from urllib.parse import urlsplit
    try:
        port = urlsplit(url).port
    except ValueError:
        return False
    return port is None or 1 <= port <= 65535

Try / catch

try:
    data = await fetch_public_resource(url)
except RemoteResourcePolicyError as e:
    if "port is invalid" in str(e):
        raise ValueError(f"configured download port in '{url}' is out of range") from e
    raise

Prevention

When it happens

Trigger: Calling fetch_public_resource with a URL containing a port like ':0' or ':70000' that survived parsing, or an integer-cast port variable interpolated into the URL that is out of range.

Common situations: Configuration or code that computes a port (e.g. defaulting to 0 when unset) and formats it into the URL; hand-built URLs in tests or scripts with placeholder ports; misconfigured proxy ports in environment settings.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at core/plugin/aitools/common/clients/safe_download.py:225

) -> None:
    if parsed.scheme.lower() not in _ALLOWED_SCHEMES:
        raise RemoteResourcePolicyError(
            "Only HTTP and HTTPS remote resources are allowed"
        )
    if not parsed.hostname:
        raise RemoteResourcePolicyError("Remote resource URL must include a hostname")
    if parsed.username is not None or parsed.password is not None:
        raise RemoteResourcePolicyError(
            "Remote resource URL must not include user information"
        )
    if "\\" in parsed.netloc:
        raise RemoteResourcePolicyError("Remote resource URL authority is invalid")
    if parsed.fragment:
        raise RemoteResourcePolicyError(
            "Remote resource URL must not include a fragment"
        )
    if port is not None and not 1 <= port <= 65535:
        raise RemoteResourcePolicyError("Remote resource URL port is invalid")


def _normalize_hostname(hostname: str) -> str:
    value = hostname.strip().lower().rstrip(".")
    if _parse_ip(value) is not None:
        return value
    try:
        normalized = URL.build(scheme="http", host=value).raw_host
    except (TypeError, ValueError, UnicodeError) as exc:
        raise RemoteResourcePolicyError("Remote resource hostname is invalid") from exc
    if not normalized:
        raise RemoteResourcePolicyError("Remote resource hostname is invalid")
    return normalized.rstrip(".")


def _parse_ip(value: str) -> Optional[IpAddress]:
    try:
        return ipaddress.ip_address(value)

View on GitHub (pinned to 5e758547a8)