{"record":{"id":"9ea814053b0bc3a2","repo":"ComposioHQ/composio","slug":"failed-to-download-file-message-status-code-s","errorCode":null,"errorMessage":"Failed to download file: {message} (status_code, status_text, download_url, mount_relative_path, filename)","messagePattern":"Failed to download file: (.+?) \\(status_code, status_text, download_url, mount_relative_path, filename\\)","errorType":"exception","errorClass":"RemoteFileDownloadError","httpStatus":null,"severity":"error","filePath":"python/composio/core/models/tool_router_session_files.py","lineNumber":215,"sourceCode":"        :func:`_fetch_url_bytes` — the same body that serves user-supplied\n        URLs — rather than a bare ``requests.get``: which side of the trust\n        boundary the URL arrived from does not change what the fetch needs to\n        defend against.\n        \"\"\"\n        try:\n            content, _ = _fetch_url_bytes(self.download_url)\n        except _UrlFetchError as e:\n            if e.redirected:\n                message = (\n                    \"Failed to download file: the download URL returned a redirect\"\n                )\n            elif e.status_code is not None:\n                message = f\"Failed to download file: {e.status_code} {e.status_text}\"\n            elif e.cause is not None:\n                message = f\"Failed to download file: {type(e.cause).__name__}\"\n            else:\n                message = f\"Failed to download file: {e}\"\n            raise RemoteFileDownloadError(\n                message,\n                status_code=e.status_code,\n                status_text=e.status_text,\n                download_url=self.download_url,\n                mount_relative_path=self.mount_relative_path,\n                filename=self.filename,\n            ) from (e.cause or e)\n        return content\n\n    def text(self) -> str:\n        \"\"\"Fetch the file content as UTF-8 text.\"\"\"\n        return self.buffer().decode(\"utf-8\")\n\n    def save(self, path: t.Optional[t.Union[str, Path]] = None) -> str:\n        \"\"\"Download and save the file to the local filesystem.\n\n        Returns the absolute path where the file was saved.\n        If path is omitted, saves to ~/.composio/files/ using the filename.","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/core/models/tool_router_session_files.py#L197-L233","documentation":"RemoteFileDownloadError raised when lazily downloading a previously uploaded session file via .buffer() (called by .text()/.save()). It enriches a failed fetch with structured fields — status_code, status_text, download_url, mount_relative_path, filename — and a message derived from the status, the exception type name, or the error string.","triggerScenarios":"Calling remote_file.buffer()/text()/save() after the file's download_url expired or was revoked, or when the storage host is unreachable/timeouts. Tests exercise success, generic failure, timeout, and download_url validation of exactly this path.","commonSituations":"Reading file contents long after the session ended and presigned storage links expired; network egress blocked from the runtime.","solutions":["Inspect e.status_code/e.download_url to identify expiry (403) vs missing (404)","Re-download promptly after upload/session creation before link expiry","If expired, re-upload or re-create the session to obtain fresh URLs"],"exampleFix":"# before\ndata = remote_file.buffer()\n\n# after\ntry:\n    data = remote_file.buffer()\nexcept RemoteFileDownloadError as e:\n    if e.status_code == 403:\n        raise RuntimeError('download link expired; re-create session') from e\n    raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from composio.core.models.tool_router_session_files import RemoteFileDownloadError\ntry:\n    data = remote_file.buffer()\nexcept RemoteFileDownloadError as e:\n    if e.status_code == 403:\n        data = refetch_or_recreate()\n    else:\n        raise","preventionTips":["Download files soon after upload","Check status_code field for expiry vs missing"],"tags":["python","files","download","remote-file","network"],"backgroundTag":"file-download-failed","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}