ATH-MaaS/Pixelle-Video · error · Exception

Failed to get upload policy: {response.text}

Error message

Failed to get upload policy: {response.text}

What it means

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.

Source

Thrown at pixelle_video/services/api_services/image_processor.py:293

            raise RuntimeError("DASHSCOPE_API_KEY 未设置,无法使用图片上传服务")
        
        headers = {
            "Authorization": f"Bearer {self.api_key}",
            "Content-Type": "application/json"
        }
        params = {
            "action": "getPolicy",
            "model": self.model_name
        }
        
        response = requests.get(
            self.UPLOAD_API_URL,
            headers=headers,
            params=params,
            proxies=self._proxies(),
        )
        if response.status_code != 200:
            raise Exception(f"Failed to get upload policy: {response.text}")
        
        return response.json()['data']
    
    def upload_file_to_oss(self, policy_data: dict, file_path: str) -> str:
        """
        将文件上传到临时存储OSS
        
        Args:
            policy_data: 上传凭证数据
            file_path: 本地文件路径
            
        Returns:
            oss_url: OSS URL (格式: oss://...)
            
        Raises:
            Exception: 上传失败时
        """
        file_name = Path(file_path).name

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Read response.text in the error to identify 401/403/429/5xx and act accordingly.
  2. Verify the API key is valid and the account has upload permission.
  3. Add throttling/backoff — the upload policy endpoint is rate limited; serialize and slow uploads.
  4. Retry with exponential backoff on 429/5xx only.

Example fix

// before
policy = processor.get_upload_policy()  # raises on 429 in a loop

// after
import time
for attempt in range(5):
    try:
        policy = processor.get_upload_policy()
        break
    except Exception as e:
        if '429' in str(e):
            time.sleep(2 ** attempt)
        else:
            raise
Defensive patterns

Strategy: retry

Validate before calling

import os
assert os.environ.get("DASHSCOPE_API_KEY"), "key required before fetching upload policy"

Type guard

def policy_ok(resp) -> bool:
    return resp is not None and resp.status_code == 200

Try / catch

import time
for attempt in range(5):
    try:
        policy = processor.get_upload_policy()
        break
    except Exception as e:
        if any(code in str(e) for code in ("429", "500", "502", "503")):
            time.sleep(2 ** attempt)
        else:
            raise  # 401/403 are not retryable

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/b43e663b394ef03b. Report an issue: GitHub.