{"record":{"id":"065fab38f5185ba2","repo":"invoke-ai/InvokeAI","slug":"failed-to-download-image-from-dashscope-status-r","errorCode":null,"errorMessage":"Failed to download image from DashScope (status {response.status_code})","messagePattern":"Failed to download image from DashScope \\(status (.+?)\\)","errorType":"exception","errorClass":"ExternalProviderRequestError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/external_generation/providers/alibabacloud.py","lineNumber":299,"sourceCode":"            raise ExternalProviderRequestError(f\"DashScope async response contained no images: {output}\")\n\n        return ExternalGenerationResult(\n            images=images,\n            seed_used=request.seed,\n            provider_request_id=request_id,\n            provider_metadata={\"model\": request.model.provider_model_id},\n        )\n\n    def _download_image(self, url: str) -> PILImageType:\n        \"\"\"Download an image from a URL and return it as a PIL Image, with a size cap.\"\"\"\n        try:\n            response = requests.get(url, timeout=_DOWNLOAD_TIMEOUT, stream=True)\n        except requests.RequestException as exc:\n            raise ExternalProviderRequestError(f\"Failed to download image from DashScope: {exc}\") from exc\n\n        with response:\n            if not response.ok:\n                raise ExternalProviderRequestError(\n                    f\"Failed to download image from DashScope (status {response.status_code})\"\n                )\n\n            content_length = response.headers.get(\"Content-Length\")\n            if content_length is not None:\n                try:\n                    if int(content_length) > _DOWNLOAD_MAX_BYTES:\n                        raise ExternalProviderRequestError(\n                            f\"DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap (Content-Length={content_length})\"\n                        )\n                except ValueError:\n                    pass\n\n            buffer = bytearray()\n            for chunk in response.iter_content(chunk_size=64 * 1024):\n                if not chunk:\n                    continue\n                buffer.extend(chunk)","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/external_generation/providers/alibabacloud.py#L281-L317","documentation":"The HTTP request for the generated image completed but returned a non-2xx status. _download_image checks response.ok inside the stream context and raises ExternalProviderRequestError embedding the status code, because the image could not be fetched.","triggerScenarios":"403/404 from an expired or region-mismatched signed URL; 403 from CDN hotlink/ACL restrictions; 410 Gone after URL TTL; 5xx from the image CDN.","commonSituations":"Downloading images long after generation once signed URLs expire; base_url region (intl vs cn) differing from the URL host region; corporate proxy blocking the CDN; transient CDN errors.","solutions":["Note the status: 403/404/410 usually means the signed URL expired — regenerate the image rather than re-fetching the old URL","Retry the full generation request to obtain fresh URLs","Ensure you consume results promptly after generation","Check that no proxy/ACL blocks access to the DashScope result-URL hosts","If 5xx, retry after a short delay"],"exampleFix":"// before\npil_image = provider._download_image(stale_url)  # 403\n// after\nresult = provider.generate(request)  # fresh URLs each run\npil_image = provider._download_image(result.images[0].url)","handlingStrategy":"retry","validationCode":"def validate_provider_config(cfg) -> None:\n    if not cfg.external_alibabacloud_api_key:\n        raise ValueError(\"DashScope API key missing\")\n    if \"dashscope\" not in (cfg.external_alibabacloud_base_url or \"dashscope-intl.aliyuncs.com\"):\n        raise ValueError(\"base_url does not look like a DashScope endpoint\")","typeGuard":null,"tryCatchPattern":"try:\n    result = provider.generate(request)\nexcept ExternalProviderRequestError as e:\n    if \"status 403\" in str(e) or \"status 404\" in str(e) or \"status 410\" in str(e):\n        log.warning(\"Image URL rejected (%s); regenerating for a fresh URL\", e)\n        result = provider.generate(request)\n    else:\n        raise","preventionTips":["Use image URLs promptly — DashScope signed URLs expire","Keep base_url region consistent with the API key's region","Ensure proxies/ACLs don't block the result-CDN hosts","Treat 5xx statuses as retryable with delay"],"tags":["http","image-download","expired-url","forbidden"],"backgroundTag":"http-4xx-response","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}