{"record":{"id":"5f34b6ac154da3ec","repo":"microsoft/autogen","slug":"error-while-downloading-files","errorCode":null,"errorMessage":"Error while downloading files","messagePattern":"Error while downloading files","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py","lineNumber":390,"sourceCode":"                        headers=headers,\n                    )\n                )\n                cancellation_token.link_future(task)\n                try:\n                    resp = await task\n                    resp.raise_for_status()\n                    local_path = self.work_dir / file\n                    local_paths.append(str(local_path))\n                    async with await open_file(local_path, \"wb\") as f:\n                        await f.write(await resp.read())\n                except asyncio.TimeoutError as e:\n                    # e.add_note is only in py 3.11+\n                    raise asyncio.TimeoutError(\"Timeout downloading files\") from e\n                except asyncio.CancelledError as e:\n                    # e.add_note is only in py 3.11+\n                    raise asyncio.CancelledError(\"Downloading files cancelled\") from e\n                except aiohttp.ClientResponseError as e:\n                    raise ConnectionError(\"Error while downloading files\") from e\n        return local_paths\n\n    async def execute_code_blocks(\n        self, code_blocks: List[CodeBlock], cancellation_token: CancellationToken\n    ) -> CodeResult:\n        \"\"\"(Experimental) Execute the code blocks and return the result.\n\n        Args:\n            code_blocks (List[CodeBlock]): The code blocks to execute.\n            cancellation_token (CancellationToken): a token to cancel the operation\n            input_files (Optional[Union[Path, str]]): Any files the code blocks will need to access\n\n        Returns:\n            CodeResult: The result of the code execution.\"\"\"\n\n        self._ensure_access_token()\n        if self._available_packages is None:\n            await self._populate_available_packages(cancellation_token)","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py#L372-L408","documentation":"Raised by AzureContainerCodeExecutor.download_files when the GET to `files/content/{file}` returns an error HTTP status (ClientResponseError re-wrapped as ConnectionError). It occurs after the existence check passed, so it usually indicates an auth or transport problem rather than a missing file.","triggerScenarios":"Downloading files when the bearer token expired between get_file_list and the content GET, when the session is reclaimed mid-download, or on 5xx from the Azure Container Apps sessions endpoint. A network failure part-way through downloading multiple files aborts the remaining files.","commonSituations":"Long download sequences of many generated artifacts outliving the access token validity; transient service errors; racing with session idle-timeout during large outputs.","solutions":["Inspect e.__cause__ for the HTTP status to distinguish auth (401/403) from transport issues","Call restart() and re-run/re-download when the session was lost (note: restart clears remote files, so the producing code must re-run)","Retry the download call: files remain on the service, so a retry after a transient failure succeeds","Batch downloads smaller or persist artifacts elsewhere if files are very large"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    paths = await executor.download_files(files, ct)\nexcept ConnectionError:\n    await asyncio.sleep(1)\n    paths = await executor.download_files(files, ct)  # files persist server-side; retry is safe","preventionTips":["Download outputs immediately after execution while the session is warm","Group downloads to minimize the number of authenticated GETs","Catch ConnectionError separately from FileNotFoundError: the former is transient, the latter means the file is absent"],"tags":["azure","network","download","files"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}