{"record":{"id":"8042c26770435000","repo":"ATH-MaaS/Pixelle-Video","slug":"dashscope-api-key","errorCode":null,"errorMessage":"DASHSCOPE_API_KEY 未设置，无法使用图片上传服务","messagePattern":"DASHSCOPE_API_KEY 未设置，无法使用图片上传服务","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/image_processor.py","lineNumber":275,"sourceCode":"            if all(is_black_pixel(pixels[width - 1 - x, y]) for y in range(height)):\n                return True\n        \n        return False\n\n    # ===== 图片上传功能 =====\n    \n    def get_upload_policy(self):\n        \"\"\"\n        获取文件上传凭证\n        \n        Returns:\n            policy_data: 包含上传所需凭证的字典\n            \n        Raises:\n            Exception: 获取上传凭证失败时\n        \"\"\"\n        if not self.api_key:\n            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}\")","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/image_processor.py#L257-L293","documentation":"get_upload_policy fetches temporary upload credentials from DashScope and raises RuntimeError when self.api_key is falsy. The DashScope upload service cannot be called without DASHSCOPE_API_KEY, so the library fails fast before making a doomed network request.","triggerScenarios":"Calling upload (which invokes get_upload_policy) on an ImageProcessor constructed without an API key, or with DASHSCOPE_API_KEY unset/empty in the environment.","commonSituations":"Environment variable not exported in the deployment environment (works locally, fails in CI/container), key passed under a different variable name, ImageProcessor instantiated without the api_key argument.","solutions":["Export DASHSCOPE_API_KEY with a valid DashScope key before running.","Pass api_key explicitly when constructing ImageProcessor.","Check the key is loaded from the right .env file and the process actually sees it (print/os.environ check).","In containers/CI, add the env var to the deployment secret configuration."],"exampleFix":"// before\nprocessor = ImageProcessor()  # no key\n\n// after\nimport os\nkey = os.environ.get(\"DASHSCOPE_API_KEY\")\nassert key, \"DASHSCOPE_API_KEY must be set\"\nprocessor = ImageProcessor(api_key=key)","handlingStrategy":"validation","validationCode":"import os\napi_key = os.environ.get(\"DASHSCOPE_API_KEY\")\nif not api_key:\n    raise RuntimeError(\"Set DASHSCOPE_API_KEY before uploading images\")","typeGuard":"def has_api_key(processor) -> bool:\n    return bool(getattr(processor, \"api_key\", None))","tryCatchPattern":"try:\n    url = processor.upload(file_path)\nexcept RuntimeError as e:\n    if \"DASHSCOPE_API_KEY\" in str(e):\n        raise ConfigError(\"Export DASHSCOPE_API_KEY in this environment\") from e\n    raise","preventionTips":["Check the env var at process startup, before any upload work","Load .env files explicitly (dotenv) and confirm os.environ sees the key","Add the key to CI/container secret configuration","Fail fast with a clear config check rather than mid-pipeline"],"tags":["dashscope","missing-api-key","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}