{"record":{"id":"319b725d6cf95dfa","repo":"microsoft/autogen","slug":"error-while-uploading-files","errorCode":null,"errorMessage":"Error while uploading files","messagePattern":"Error while uploading 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":352,"sourceCode":"                            url,\n                            headers=headers,\n                            data=data,\n                        )\n                    )\n\n                    cancellation_token.link_future(task)\n                    try:\n                        resp = await task\n                        resp.raise_for_status()\n\n                    except asyncio.TimeoutError as e:\n                        # e.add_note is only in py 3.11+\n                        raise asyncio.TimeoutError(\"Timeout uploading files\") from e\n                    except asyncio.CancelledError as e:\n                        # e.add_note is only in py 3.11+\n                        raise asyncio.CancelledError(\"Uploading files cancelled\") from e\n                    except aiohttp.ClientResponseError as e:\n                        raise ConnectionError(\"Error while uploading files\") from e\n\n    async def download_files(self, files: List[Union[Path, str]], cancellation_token: CancellationToken) -> List[str]:\n        self._ensure_access_token()\n        available_files = await self.get_file_list(cancellation_token)\n        # TODO: Better to use the client auth system rather than headers\n        headers = {\"Authorization\": f\"Bearer {self._access_token}\"}\n        timeout = aiohttp.ClientTimeout(total=float(self._timeout))\n        local_paths: List[str] = []\n        async with aiohttp.ClientSession(timeout=timeout) as client:\n            for file in files:\n                if file not in available_files:\n                    # TODO: what's the right thing to do here?\n                    raise FileNotFoundError(f\"{file} does not exist\")\n\n                url = self._construct_url(f\"files/content/{file}\")\n\n                task = asyncio.create_task(\n                    client.get(","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py#L334-L370","documentation":"Raised by AzureContainerCodeExecutor.upload_files when the POST to the session's `files/upload` endpoint returns an error HTTP status (aiohttp raise_for_status -> ClientResponseError, re-wrapped as ConnectionError). Partial uploads may already have occurred because the loop uploads files one at a time.","triggerScenarios":"Calling upload_files while the bearer token is expired/invalid (401), the session has been reclaimed (404), the upload exceeds service size limits (413), or the service returns 5xx. Any single file's failed POST aborts the entire call with this error.","commonSituations":"Uploading large data files over a slow link after the token's validity window passed; uploading to a session that idled out between code executions; intermittent Azure Container Apps throttling during bursts of uploads.","solutions":["Inspect e.__cause__ (aiohttp.ClientResponseError) for the exact status: 401/403 -> token issue, 404 -> stale session, 413 -> file too large","Call restart() and re-upload to get a fresh session and token","Compress or split very large files if hitting size limits","Retry with exponential backoff for transient 5xx/network failures"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"async def upload_with_retry(executor, files, ct, attempts=3):\n    for i in range(attempts):\n        try:\n            return await executor.upload_files(files, ct)\n        except ConnectionError as e:\n            status = getattr(e.__cause__, \"status\", None)\n            if status in (401, 403, 404) and i == 0:\n                await executor.restart()\n                continue\n            if i == attempts - 1 or (status and status < 500):\n                raise\n            await asyncio.sleep(2 ** i)","preventionTips":["Upload promptly after creating the executor so the token is fresh","Compress large files before upload to stay under service limits","Batch uploads and retry only the remaining files after a mid-loop failure"],"tags":["azure","network","upload","files"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}