XX-net/XX-Net · error

api:%s fail:%s t:%d

Error message

api:%s fail:%s t:%d

What it means

call_api performed an HTTP request to the control-plane API and got a non-200 status (including exceptions/None responses from the loop). It logs path, 'status:%r' reason and time cost, sets g.last_api_error, and returns (False, reason).

Source

Thrown at code/default/x_tunnel/local/proxy_session.py:1195

    try:
        upload_post_data = json.dumps(req_info)
        upload_post_data = encrypt_data(upload_post_data)

        start_time = time.time()
        while time.time() - start_time < 30:
            content, status, response = g.http_client.request(method="POST", host=g.config.api_server, path=path,
                                                              headers={"Content-Type": "application/json"},
                                                              data=upload_post_data, timeout=5)
            if status >= 400:
                time.sleep(1)
                continue
            else:
                break

        time_cost = time.time() - start_time
        if status != 200:
            reason = "status:%r" % status
            xlog.warn("api:%s fail:%s t:%d", path, reason, time_cost)
            g.last_api_error = reason
            return False, reason

        content = decrypt_data(content)
        if isinstance(content, memoryview):
            content = content.tobytes()

        content = utils.to_str(content)
        try:
            info = json.loads(content)
        except Exception as e:
            g.last_api_error = "parse json fail"
            xlog.warn("api:%s parse json:%s fail:%r", path, content, e)
            return False, "parse json fail"

        res = info["res"]
        if res != "success":
            g.last_api_error = info["reason"]

View on GitHub (pinned to cfa5bc17b6)

Solutions

  1. Inspect g.last_api_error / log for the exact status code; 5xx means server issue, retry later
  2. Verify network reachability of the API host
  3. Re-login to refresh session/token if status is 401/403
  4. Update XX-Net if API endpoint changed
Defensive patterns

Strategy: retry

Validate before calling

import socket
socket.create_connection((api_host, 443), timeout=5).close()  # preflight reachability

Try / catch

ok, reason = call_api(path)
if not ok:
    if 'status:5' in str(reason):
        time.sleep(backoff); retry()

Prevention

When it happens

Trigger: Any of check_report_status / request_balance / req_reset_password / req_order_handler / req_transfer_handler / req_get_history_handler hitting a non-200: 5xx from server, 4xx auth errors, timeouts surfacing as non-200 status.

Common situations: Server outage or maintenance, expired auth token, network blocking the API host, or redirects not followed.

Related errors


AI-assisted analysis of XX-net/XX-Net@cfa5bc17b6 (2026-08-27). Data as JSON: /api/errors/ef0ced63d41ffc90. Report an issue: GitHub.