{"record":{"id":"b43e663b394ef03b","repo":"ATH-MaaS/Pixelle-Video","slug":"failed-to-get-upload-policy-response-text","errorCode":null,"errorMessage":"Failed to get upload policy: {response.text}","messagePattern":"Failed to get upload policy: (.+?)","errorType":"http","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/image_processor.py","lineNumber":293,"sourceCode":"            raise RuntimeError(\"DASHSCOPE_API_KEY 未设置，无法使用图片上传服务\")\n        \n        headers = {\n            \"Authorization\": f\"Bearer {self.api_key}\",\n            \"Content-Type\": \"application/json\"\n        }\n        params = {\n            \"action\": \"getPolicy\",\n            \"model\": self.model_name\n        }\n        \n        response = requests.get(\n            self.UPLOAD_API_URL,\n            headers=headers,\n            params=params,\n            proxies=self._proxies(),\n        )\n        if response.status_code != 200:\n            raise Exception(f\"Failed to get upload policy: {response.text}\")\n        \n        return response.json()['data']\n    \n    def upload_file_to_oss(self, policy_data: dict, file_path: str) -> str:\n        \"\"\"\n        将文件上传到临时存储OSS\n        \n        Args:\n            policy_data: 上传凭证数据\n            file_path: 本地文件路径\n            \n        Returns:\n            oss_url: OSS URL (格式: oss://...)\n            \n        Raises:\n            Exception: 上传失败时\n        \"\"\"\n        file_name = Path(file_path).name","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/image_processor.py#L275-L311","documentation":"get_upload_policy raises Exception when the DashScope upload-policy endpoint returns a non-200 HTTP status; the raw response body is included in the message. This indicates the credential request itself failed (auth, rate limit, or server error) before any file is uploaded.","triggerScenarios":"POST/GET to UPLOAD_API_URL returns 401 (bad key), 403 (no permission), 429 (upload-policy endpoint rate limited — the docstring notes it is limited), or 5xx server error.","commonSituations":"Hitting DashScope's upload-policy rate limit by uploading many files in a tight loop, invalid/expired API key, region/account without the upload feature enabled, DashScope incident causing 5xx.","solutions":["Read response.text in the error to identify 401/403/429/5xx and act accordingly.","Verify the API key is valid and the account has upload permission.","Add throttling/backoff — the upload policy endpoint is rate limited; serialize and slow uploads.","Retry with exponential backoff on 429/5xx only."],"exampleFix":"// before\npolicy = processor.get_upload_policy()  # raises on 429 in a loop\n\n// after\nimport time\nfor attempt in range(5):\n    try:\n        policy = processor.get_upload_policy()\n        break\n    except Exception as e:\n        if '429' in str(e):\n            time.sleep(2 ** attempt)\n        else:\n            raise","handlingStrategy":"retry","validationCode":"import os\nassert os.environ.get(\"DASHSCOPE_API_KEY\"), \"key required before fetching upload policy\"","typeGuard":"def policy_ok(resp) -> bool:\n    return resp is not None and resp.status_code == 200","tryCatchPattern":"import time\nfor attempt in range(5):\n    try:\n        policy = processor.get_upload_policy()\n        break\n    except Exception as e:\n        if any(code in str(e) for code in (\"429\", \"500\", \"502\", \"503\")):\n            time.sleep(2 ** attempt)\n        else:\n            raise  # 401/403 are not retryable","preventionTips":["Throttle uploads — the policy endpoint is rate limited","Only retry on 429/5xx; fail fast on 401/403","Verify key validity and upload permission before batch jobs","Log response.text from errors for provider-side diagnostics"],"tags":["dashscope","http-error","upload"],"backgroundTag":"http-request-failed","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}