{"record":{"id":"114116f4fab92c9d","repo":"invoke-ai/InvokeAI","slug":"failed-to-download-image-from-dashscope-exc","errorCode":null,"errorMessage":"Failed to download image from DashScope: {exc}","messagePattern":"Failed to download image from DashScope: (.+?)","errorType":"exception","errorClass":"ExternalProviderRequestError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/external_generation/providers/alibabacloud.py","lineNumber":295,"sourceCode":"                pil_image = decode_image_base64(b64_image)\n                images.append(ExternalGeneratedImage(image=pil_image, seed=request.seed))\n\n        if not images:\n            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()","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/external_generation/providers/alibabacloud.py#L277-L313","documentation":"_download_image fetches generated image URLs with requests.get(stream=True). Any requests.RequestException (DNS failure, connection reset, TLS error, timeout after _DOWNLOAD_TIMEOUT=60s) is wrapped and re-raised as ExternalProviderRequestError with the underlying exception text.","triggerScenarios":"The image host is unreachable; the returned image URL has expired (DashScope URLs are time-limited); DNS/proxy issues in the deployment environment; network outage mid-generation; TLS interception by corporate proxies.","commonSituations":"Delaying image download until after DashScope's signed URL TTL expires (typically ~24h, but can be shorter); air-gapped/egress-restricted clusters where the app host cannot reach the CDN host; flaky container networking.","solutions":["Retry the generation — the provider does not retry image downloads, only API calls","Check egress/firewall rules so the app host can reach the DashScope CDN hosts","Download promptly after generation; expired signed URLs cause connection/HTTP failures","Verify DNS and proxy settings (HTTP_PROXY/HTTPS_PROXY) in the deployment environment","Test the failing URL with curl from the same host to isolate network vs code issues"],"exampleFix":"// before\nresponse = requests.get(url, timeout=_DOWNLOAD_TIMEOUT, stream=True)\n// after\nfor attempt in range(3):\n    try:\n        response = requests.get(url, timeout=_DOWNLOAD_TIMEOUT, stream=True)\n        break\n    except requests.RequestException:\n        if attempt == 2:\n            raise\n        time.sleep(2 ** attempt)","handlingStrategy":"retry","validationCode":"import socket, requests\ndef can_reach_host(url: str) -> bool:\n    try:\n        host = requests.utils.urlparse(url).hostname\n        socket.getaddrinfo(host, 443)\n        return True\n    except (socket.gaierror, ValueError):\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    result = provider.generate(request)\nexcept ExternalProviderRequestError as e:\n    if \"Failed to download image from DashScope:\" in str(e):\n        log.warning(\"Transient image-download failure, retrying: %s\", e)\n        result = provider.generate(request)\n    else:\n        raise","preventionTips":["Consume and download results immediately after generation before URLs expire","Open egress to DashScope CDN hosts from your deployment","Set correct HTTP_PROXY/HTTPS_PROXY/NO_PROXY in containers","Add a short retry with backoff around generate() for network flakiness"],"tags":["network","http","image-download","timeout"],"backgroundTag":"connection-refused","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}