NanmiCoder/MediaCrawler · error · Exception

not match kuaidaili proxy info

Error message

not match kuaidaili proxy info

What it means

Intended to fire when re.search() finds no capture groups for the pattern '(ip):(port),(digits)' in the KuaiDaiLi proxy string. In practice this raise is dead code: when the pattern does not match, re.search() returns None and match.groups() raises AttributeError ('NoneType' object has no attribute 'groups') on the line above. The only way to see this exact message is a zero-group match, which this regex cannot produce.

Source

Thrown at proxy/providers/kuaidl_proxy.py:63


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:
            kdl_user_name:
            kdl_user_pwd:
        """
        self.kdl_user_name = kdl_user_name
        self.kdl_user_pwd = kdl_user_pwd

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Fix the guard order: check `if match is None:` before touching match.groups() so a clean error is raised instead of AttributeError
  2. Log the offending proxy_info value when parsing fails to identify which entry from proxy_list is malformed
  3. Validate the entry against the regex yourself before passing it in: re.search(r'(\d{1,3}\.){3}\d{1,3}:\d{1,5},\d+', entry)
  4. If entries are hostnames, extend the pattern to accept [\w.-]+ instead of the dotted-quad

Example fix

// before
match = re.search(pattern, proxy_info)
if not match.groups():
    raise Exception("not match kuaidaili proxy info")

// after
match = re.search(pattern, proxy_info)
if match is None:
    raise ValueError(f"not match kuaidaili proxy info: {proxy_info!r}")
Defensive patterns

Strategy: validation

Validate before calling

KDL_RE = re.compile(r"(\d{1,3}\.){3}\d{1,3}:\d{1,5},\d+")

if not KDL_RE.search(proxy_info):
    raise ValueError(f"bad kdl proxy format: {proxy_info!r}")
# only now call parse_kuaidaili_proxy(proxy_info)

Type guard

def matches_kdl_pattern(s: str) -> bool:
    return isinstance(s, str) and KDL_RE.search(s) is not None

Try / catch

try:
    model = parse_kuaidaili_proxy(proxy_info)
except (ValueError, AttributeError) as e:
    # AttributeError: re.search returned None and the buggy guard dereferenced it
    utils.logger.error(f"kdl parse failed for {proxy_info!r}: {e!r}")
    raise IpGetError("unparseable kuaidaili proxy entry") from e

Prevention

When it happens

Trigger: A proxy_list entry whose ip:port,expire shape deviates from the regex — hostname instead of dotted-quad IP, port longer than 5 digits, non-digit expire field, or extra whitespace. Instead of this message you will typically see the AttributeError from the same region; the underlying input condition is identical.

Common situations: KuaiDaiLi returning a domain-based proxy entry, a truncated response due to encoding issues, or a proxy string built by hand in tests that does not match the wire format.

Related errors


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