iflytek/astron-agent · error · ValueError

Bad IP !!

Error message

Bad IP !! {localIp}

What it means

SidGenerator2.__init__ converts localIp via socket.inet_aton and builds a short 4-hex-char IP suffix; if inet_aton cannot parse the string (the else branch is reached only when ip is falsy/invalid) it raises ValueError("Bad IP !! <ip>"). Effectively this means the localIp argument is not a valid dotted-quad IPv4 address (e.g. empty, hostname, or IPv6 string).

Solutions

  1. Pass a valid dotted-quad IPv4 string (e.g. '10.0.1.23') as localIp — resolve hostnames with socket.gethostbyname first.
  2. Fix the env/config supplying the pod IP (e.g. status.podIP in Kubernetes) so it is not empty or '::1'.
  3. Add a pre-check: socket.inet_aton(localIp) in a try/except before constructing SidGenerator2.
  4. In IPv6-only clusters, ensure the pod advertises an IPv4 address or adapt the generator.

Example fix

// before
gen = SidGenerator2(sub, loc, os.getenv("POD_IP", ""), port)
// after
ip = os.getenv("POD_IP") or socket.gethostbyname(socket.gethostname())
socket.inet_aton(ip)  # fail fast with a clear message
gen = SidGenerator2(sub, loc, ip, port)
Defensive patterns

Strategy: validation

Validate before calling

import socket
def valid_ipv4(s):
    try:
        socket.inet_aton(s)
        return True
    except OSError:
        return False
assert valid_ipv4(pod_ip), f"invalid localIp: {pod_ip!r}"

Type guard

def is_ipv4(s):
    if not isinstance(s, str) or not s:
        return False
    try:
        socket.inet_aton(s)
        return True
    except OSError:
        return False

Try / catch

try:
    gen = SidGenerator2(sub, location, local_ip, local_port)
except ValueError as e:
    logger.error(f"sid generator config invalid: {e}")
    raise

Prevention

When it happens

Trigger: Constructing SidGenerator2(sub, location, localIp, localPort) where localIp is empty, a hostname like 'localhost', an IPv6 address, or otherwise not parseable by socket.inet_aton as IPv4.

Common situations: Service discovery returning a hostname instead of an IP; env var for the pod IP unset or empty in local development; containerized environments reporting IPv6 or '::1'.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at core/workflow/extensions/otlp/sid/sid_generator2.py:71

        :param localIp: Local IP address (must be valid IPv4)
        :param localPort: Local port number (must be at least 4 characters)
        :raises ValueError: If IP address is invalid or port is too short
        """
        # Initialize sequential index counter
        self.index = 0

        # Parse and validate IP address
        ip = socket.inet_aton(localIp)
        if ip:
            # Extract the last two octets of the IP address
            ipSec3 = ip[2]
            ipSec4 = ip[3]
            ip3 = ipSec3 & 0xFF
            ip4 = ipSec4 & 0xFF
            # Create short IP representation using last two octets
            self.ShortLocalIP = f"{ip3:02x}{ip4:02x}"
        else:
            raise ValueError("Bad IP !! " + localIp)

        # Validate port number length
        if len(localPort) < 4:
            raise ValueError("Bad Port!! ")

        # Store configuration parameters
        self.port = localPort
        self.location = location
        self.sub = sub
        logger.debug("✅ SID generator initialized successfully")

    def gen(self) -> str:
        """
        Generate a unique session identifier.

        The SID format is: {sub}{pid}{index}@{location}{timestamp}{ip}{port}{version}

        :return: A unique session identifier string

View on GitHub (pinned to 5e758547a8)