{"record":{"id":"941fe0e075afe127","repo":"ATH-MaaS/Pixelle-Video","slug":"api-code-data-get-code-message-dat","errorCode":null,"errorMessage":"可灵查询 API 错误: code={data.get('code')}, message={data.get('message')}","messagePattern":"可灵查询 API 错误: code=(.+?), message=(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/video_kling.py","lineNumber":285,"sourceCode":"        查询单个任务状态\n\n        Returns:\n            API 响应中的 data 字段\n        \"\"\"\n        url = f\"{self.base_url}/v1/videos/{endpoint}/{task_id}\"\n        headers = self._auth_headers()\n\n        resp = self._session.get(\n            url,\n            headers=headers,\n            timeout=30,\n            proxies=_proxy_dict(self.local_proxy),\n        )\n        resp.raise_for_status()\n        data = resp.json()\n\n        if data.get(\"code\") != 0:\n            raise RuntimeError(\n                f\"可灵查询 API 错误: code={data.get('code')}, message={data.get('message')}\"\n            )\n\n        return data[\"data\"]\n\n    # ─── 轮询等待 ───\n\n    def _poll_until_done(self, task_id: str, endpoint: str = \"image2video\") -> dict:\n        \"\"\"\n        轮询任务直到完成或失败\n\n        Returns:\n            任务结果数据\n\n        Raises:\n            RuntimeError: 任务失败\n            TimeoutError: 超过最大轮询次数\n        \"\"\"","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/video_kling.py#L267-L303","documentation":"The Kling task-status query endpoint returned HTTP 200 but with a non-zero business code. _query_task raises RuntimeError with the API's code/message instead of returning data, so the polling loop in _poll_until_done aborts.","triggerScenarios":"GET /v1/videos/{endpoint}/{task_id} returns {\"code\": <non-zero>, \"message\": ...} (video_kling.py:284-287) — usually task_id not found (wrong task id or task expired/removed server-side), auth failure on the polling call, or querying against the wrong endpoint (image2video vs text2video mismatch).","commonSituations":"Polling a task_id generated by a different endpoint type, JWT expired mid-poll after a long generation, task purged by Kling retention policy before polling started, or transient API-side errors surfacing as non-zero codes.","solutions":["Check the code/message: auth errors -> refresh credentials; task-not-found -> verify the task_id and that the endpoint matches how the task was submitted.","Ensure _poll_until_done passes the same endpoint used in _submit_task (image2video if an image was supplied, else text2video).","If the code indicates a transient server error, add retry with backoff around _query_task before failing the whole poll loop.","Start polling promptly after submission so the task isn't purged before the first query."],"exampleFix":"# before\nresult = self._query_task(task_id, endpoint=\"image2video\")  # task submitted via text2video\n# after\nendpoint = \"image2video\" if image_path else \"text2video\"\nresult = self._query_task(task_id, endpoint=endpoint)","handlingStrategy":"retry","validationCode":"def can_query(task_id: str) -> bool:\n    return bool(task_id) and isinstance(task_id, str)  # 并确保 endpoint 与提交时一致\nendpoint = \"image2video\" if used_image else \"text2video\"","typeGuard":null,"tryCatchPattern":"try:\n    result = client._query_task(task_id, endpoint=endpoint)\nexcept RuntimeError as e:\n    if \"任务不存在\" in str(e) or \"not found\" in str(e).lower():\n        raise  # task_id/endpoint 错误，重试无意义\n    time.sleep(3)  # 瞬时错误，退避后重查\n    result = client._query_task(task_id, endpoint=endpoint)","preventionTips":["Always pass the same endpoint used at submission into every poll","Refresh JWT before long polls so credentials don't expire mid-generation","Query the task promptly after submission to avoid retention cleanup","Log the API code to distinguish auth vs not-found vs transient errors"],"tags":["kling","api-error","polling","task-not-found"],"backgroundTag":"api-business-error","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}