NanmiCoder/MediaCrawler · error · Exception

not invalid kuaidaili proxy info

Error message

not invalid kuaidaili proxy info

What it means

Thrown by parse_kuaidaili_proxy() when the proxy string returned by the KuaiDaiLi API cannot be split on ':' into exactly two parts. The expected wire format is 'IP:PORT,EXPIRE_SECONDS' (e.g. '1.2.3.4:8080,120'), so exactly one colon is allowed. Any deviation — extra colons, a missing port, an empty string — fails this pre-check before the regex stage.

Source

Thrown at proxy/providers/kuaidl_proxy.py:58

class KuaidailiProxyModel(BaseModel):
    ip: str = Field("ip")
    port: int = Field("port")
    expire_ts: int = Field("Expiration time, in seconds, how many seconds until expiration")


def parse_kuaidaili_proxy(proxy_info: str) -> KuaidailiProxyModel:
    """
    Parse KuaiDaili IP information
    Args:
        proxy_info:

    Returns:

    """
    proxies: List[str] = proxy_info.split(":")
    if len(proxies) != 2:
        raise Exception("not invalid kuaidaili proxy info")

    pattern = r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5}),(\d+)'
    match = re.search(pattern, proxy_info)
    if not match.groups():
        raise Exception("not match kuaidaili proxy info")

    return KuaidailiProxyModel(
        ip=match.groups()[0],
        port=int(match.groups()[1]),
        expire_ts=int(match.groups()[2])
    )


class KuaiDaiLiProxy(ProxyProvider):
    def __init__(self, kdl_user_name: str, kdl_user_pwd: str, kdl_secret_id: str, kdl_signature: str):
        """

        Args:

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Verify the raw value: log response.json()['data']['proxy_list'] and confirm each entry looks like '1.2.3.4:8080,120'
  2. If entries carry credentials ('user:pass@ip:port,ttl'), switch the KuaiDaiLi order type back to API extraction or strip the credential prefix before parsing
  3. If the entry lacks ',expire', the API order/params are wrong — check the 'pt' and 'format' params sent in self.params for the GetKdlIp endpoint
  4. Normalize the input before calling: split on the last ':' and re-join so only ip:port,expire remains

Example fix

// before
proxies: List[str] = proxy_info.split(":")
if len(proxies) != 2:
    raise Exception("not invalid kuaidaili proxy info")

// after (tolerate credential-prefixed format)
info = proxy_info.split("@")[-1]  # strip user:pass@ prefix if present
host_part, _, expire = info.partition(",")
if "," not in info or ":" not in host_part:
    raise ValueError(f"not invalid kuaidaili proxy info: {proxy_info!r}")
Defensive patterns

Strategy: validation

Validate before calling

import re

def is_valid_kuaidaili_proxy(s: str) -> bool:
    if not isinstance(s, str) or s.count(":") != 1:
        return False
    return re.fullmatch(r"(\d{1,3}\.){3}\d{1,3}:\d{1,5},\d+", s) is not None

# before parsing:
# assert is_valid_kuaidaili_proxy(entry), f"bad kdl entry {entry!r}"

Type guard

def is_kuaidaili_proxy_str(s: str) -> bool:
    return (
        isinstance(s, str)
        and s.count(":") == 1
        and re.fullmatch(r"(\d{1,3}\.){3}\d{1,3}:\d{1,5},\d+", s) is not None
    )

Try / catch

try:
    model = parse_kuaidaili_proxy(entry)
except (Exception,) as e:
    utils.logger.error(f"skipping malformed kdl proxy {entry!r}: {e}")
    continue  # skip bad entries, keep the rest of the batch

Prevention

When it happens

Trigger: Calling KuaiDaiLiProxy.get_proxies() and the provider's data.proxy_list entries arrive as 'user:pass@ip:port,expire' (credential-prefixed format from a tunnel/order type change) or as bare 'ip:port' without the trailing ',expire' field. Also triggered if the API response format changes or the entry is an empty string.

Common situations: Switching KuaiDaiLi order types (exclusive tunnel vs API extraction) changes the proxy_list entry shape; a KuaiDaiLi API version change; mistakenly feeding a proxy string from a different provider (e.g. Wandou format) into this parser.

Related errors


AI-assisted analysis of NanmiCoder/MediaCrawler@d6f7c5bb90 (2026-08-15). Data as JSON: /api/errors/7bde635949e87fec. Report an issue: GitHub.