{"record":{"id":"d2b528a5c5c58880","repo":"XX-net/XX-Net","slug":"login-session-fail-status-r","errorCode":null,"errorMessage":"login session fail, status:%r","messagePattern":"login session fail, status:%r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"code/default/x_tunnel/local/proxy_session.py","lineNumber":429,"sourceCode":"                upload_data_head += struct.pack(\"<H\", len(extra_info)) + utils.to_bytes(extra_info)\n\n                upload_post_data = encrypt_data(upload_data_head)\n\n                content, status, response = g.http_client.request(method=\"POST\", host=g.server_host, path=\"/data\",\n                                                                  data=upload_post_data,\n                                                                  timeout=g.config.network_timeout)\n\n                time_cost = time.time() - start_time\n\n                if status == 521:\n                    g.last_api_error = \"session server is down.\"\n                    xlog.warn(\"login session server is down, try get new server.\")\n                    g.server_host = None\n                    return False\n\n                if status != 200:\n                    g.last_api_error = \"session server login fail:%r\" % status\n                    xlog.warn(\"login session fail, status:%r\", status)\n                    continue\n\n                if len(content) < 6:\n                    g.last_api_error = \"session server protocol fail, login res len:%d\" % len(content)\n                    xlog.error(\"login data len:%d fail\", len(content))\n                    continue\n\n                info = decrypt_data(content)\n                magic, protocol_version, pack_type, res, message_len = struct.unpack(\"<cBBBH\", info[:6])\n                message = info[6:]\n                if isinstance(message, memoryview):\n                    message = message.tobytes()\n\n                if magic != b\"P\" or protocol_version != g.protocol_version or pack_type != 1:\n                    xlog.error(\"login_session time:%d head error:%s\", 1000 * time_cost, utils.str2hex(info[:6]))\n                    return False\n\n                if res != 0:","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/proxy_session.py#L411-L447","documentation":"login_session got a non-200, non-521 HTTP status from the session login API (e.g. 401/403/5xx). The status is recorded in g.last_api_error and the retry loop continues to attempt logins. Typical meanings: authentication failure for the account credentials, expired token, rate limiting, or server-side errors.","triggerScenarios":"Logging in with invalid/expired X-Tunnel credentials, hitting rate limits, or API server errors — any status other than 200/521 from the login endpoint.","commonSituations":"Changed account password, expired session token reused, too many login attempts, API under maintenance.","solutions":["Inspect the exact status code (401/403 → re-enter credentials; 429 → back off; 5xx → server issue)","Re-verify the X-Tunnel account credentials/token in config","Add exponential backoff between login retries instead of a tight continue loop","Check community/status channels if the API is failing server-side for everyone"],"exampleFix":"# before\nif status != 200:\n    g.last_api_error = \"session server login fail:%r\" % status\n    xlog.warn(\"login session fail, status:%r\", status)\n    continue\n\n# after\nif status != 200:\n    g.last_api_error = \"session server login fail:%r\" % status\n    xlog.warn(\"login session fail, status:%r\", status)\n    time.sleep(min(60, 2 ** attempt))  # backoff\n    continue","handlingStrategy":"retry","validationCode":"if not credentials_valid():\n    refresh_x_tunnel_token()  # before calling session.start()","typeGuard":null,"tryCatchPattern":"for attempt in range(5):\n    if session.start(): break\n    if '401' in str(g.last_api_error) or '403' in str(g.last_api_error):\n        re_prompt_credentials(); break\n    time.sleep(2 ** attempt)","preventionTips":["Keep X-Tunnel credentials/token current","Back off between login retries; inspect g.last_api_error for the status code","Distinguish auth errors (fix credentials) from 5xx (wait/retry)"],"tags":["x-tunnel","login","http-status","authentication"],"backgroundTag":"login-api-failure","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}