{"record":{"id":"a393c33463034f1d","repo":"ComposioHQ/composio","slug":"error-downloading-file-sanitize-url-for-logging","errorCode":null,"errorMessage":"Error downloading file: {_sanitize_url_for_logging(self.s3url)}. Error: {type(e).__name__}","messagePattern":"Error downloading file: (.+?)\\. Error: (.+?)","errorType":"exception","errorClass":"ErrorDownloadingFile","httpStatus":null,"severity":"error","filePath":"python/composio/core/models/_files.py","lineNumber":722,"sourceCode":"            streamed byte count is authoritative because ``Content-Length`` can\n            be absent or dishonest.\n        \"\"\"\n        # SEC-316: `self.name` also comes from the (potentially compromised or\n        # MITM'd) API response. Collapsed to a bare filename and checked against\n        # `root` — not `outdir` — so a name like `output_evil/foo`\n        # (sibling-prefix attack) is rejected too.\n        try:\n            outfile = secure_basename_join(outdir, self.name, root=root)\n        except UnsafePathComponentError as e:\n            raise ErrorDownloadingFile(str(e)) from e\n        try:\n            response = safe_get(\n                self.s3url,\n                stream=True,\n                timeout=(_CONNECT_TIMEOUT, _READ_TIMEOUT),\n            )\n        except requests.exceptions.RequestException as e:\n            raise ErrorDownloadingFile(\n                \"Error downloading file: \"\n                f\"{_sanitize_url_for_logging(self.s3url)}. Error: {type(e).__name__}\"\n            ) from e\n        if response.status_code != 200:\n            response.close()\n            raise ErrorDownloadingFile(\n                f\"Error downloading file: {_sanitize_url_for_logging(self.s3url)}\"\n            )\n\n        # Early abort for a self-declared oversized body. The header is only a\n        # hint — `parse_content_length` returns None for anything untrustworthy\n        # and the streaming counter below is the authoritative limit.\n        content_length = parse_content_length(response.headers.get(\"Content-Length\"))\n        if content_length is not None and content_length > max_size:\n            response.close()\n            raise ResponseTooLargeError(\n                f\"File size ({content_length} bytes) exceeds maximum allowed \"\n                f\"size ({max_size} bytes)\"","sourceCodeStart":704,"sourceCodeEnd":740,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/core/models/_files.py#L704-L740","documentation":"The GET to the file's S3 URL during download raised a requests RequestException (connection error, DNS failure, TLS problem, timeout at transport level). The error type name and sanitized URL are reported.","triggerScenarios":"FileModel.download when the runtime cannot reach the S3/CDN host of model.s3url — network outage, egress firewall, proxy blocking object storage, expired DNS.","commonSituations":"Restricted CI/container networks blocking *.amazonaws.com or the CDN; transient connectivity blips; misconfigured HTTPS_PROXY; air-gapped environments.","solutions":["Verify the s3url host is reachable from the runtime (curl -I).","Retry the download — transient errors are common.","Fix proxy/TLS configuration if a middlebox is interfering.","Check DNS resolution for the bucket host."],"exampleFix":"# before\npath = model.download()\n# after\nfrom tenacity import retry, wait_exponential, stop_after_attempt\n@retry(wait=wait_exponential(multiplier=1), stop=stop_after_attempt(4))\ndef safe_download():\n    return model.download()\npath = safe_download()","handlingStrategy":"retry","validationCode":"import socket\nfrom urllib.parse import urlparse\n\ndef s3_reachable(url: str) -> bool:\n    host = urlparse(url).hostname or ''\n    try:\n        socket.create_connection((host, 443), timeout=5).close()\n        return True\n    except OSError:\n        return False","typeGuard":null,"tryCatchPattern":"from composio.core.models._files import ErrorDownloadingFile\n\nfor attempt in range(3):\n    try:\n        path = model.download()\n        break\n    except ErrorDownloadingFile as e:\n        if attempt == 2:\n            raise\n        time.sleep(2 ** attempt)","preventionTips":["Allowlist object-storage egress in firewall/proxy rules.","Retry downloads with exponential backoff for transient failures.","Monitor DNS/TLS health in the runtime environment."],"tags":["python","network","s3","download","connection-error"],"backgroundTag":"s3-download-failed","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}