microsoft/autogen · error · ConnectionError
Error while uploading files
Error message
Error while uploading files
What it means
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.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py:352
url,
headers=headers,
data=data,
)
)
cancellation_token.link_future(task)
try:
resp = await task
resp.raise_for_status()
except asyncio.TimeoutError as e:
# e.add_note is only in py 3.11+
raise asyncio.TimeoutError("Timeout uploading files") from e
except asyncio.CancelledError as e:
# e.add_note is only in py 3.11+
raise asyncio.CancelledError("Uploading files cancelled") from e
except aiohttp.ClientResponseError as e:
raise ConnectionError("Error while uploading files") from e
async def download_files(self, files: List[Union[Path, str]], cancellation_token: CancellationToken) -> List[str]:
self._ensure_access_token()
available_files = await self.get_file_list(cancellation_token)
# TODO: Better to use the client auth system rather than headers
headers = {"Authorization": f"Bearer {self._access_token}"}
timeout = aiohttp.ClientTimeout(total=float(self._timeout))
local_paths: List[str] = []
async with aiohttp.ClientSession(timeout=timeout) as client:
for file in files:
if file not in available_files:
# TODO: what's the right thing to do here?
raise FileNotFoundError(f"{file} does not exist")
url = self._construct_url(f"files/content/{file}")
task = asyncio.create_task(
client.get(View on GitHub (pinned to 027ecf0a37)
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
Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
null
Try / catch
async def upload_with_retry(executor, files, ct, attempts=3):
for i in range(attempts):
try:
return await executor.upload_files(files, ct)
except ConnectionError as e:
status = getattr(e.__cause__, "status", None)
if status in (401, 403, 404) and i == 0:
await executor.restart()
continue
if i == attempts - 1 or (status and status < 500):
raise
await asyncio.sleep(2 ** i) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error while getting file list
- {file} does not exist
- Error while downloading files
- {logs_all}
- No stop reason found
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/319b725d6cf95dfa.
Report an issue: GitHub.