{"record":{"id":"b4a16949a47a1f17","repo":"crewAIInc/crewAI","slug":"error-fetching-content-from-url-url-e-s","errorCode":null,"errorMessage":"Error fetching content from URL {url}: {e!s}","messagePattern":"Error fetching content from URL (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/rag/loaders/docx_loader.py","lineNumber":53,"sourceCode":"    def _download_from_url(url: str, kwargs: dict[str, Any]) -> str:\n        headers = kwargs.get(\n            \"headers\",\n            {\n                \"Accept\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n                \"User-Agent\": \"Mozilla/5.0 (compatible; crewai-tools DOCXLoader)\",\n            },\n        )\n\n        try:\n            response = safe_get(url, headers=headers, timeout=30)\n            response.raise_for_status()\n\n            # Create temporary file to save the DOCX content\n            with tempfile.NamedTemporaryFile(suffix=\".docx\", delete=False) as temp_file:\n                temp_file.write(response.content)\n                return temp_file.name\n        except Exception as e:\n            raise ValueError(f\"Error fetching content from URL {url}: {e!s}\") from e\n\n    def _load_from_file(\n        self,\n        file_path: str,\n        source_ref: str,\n        DocxDocument: Any,  # noqa: N803\n    ) -> LoaderResult:\n        try:\n            doc = DocxDocument(file_path)\n\n            text_parts = []\n            for paragraph in doc.paragraphs:\n                if paragraph.text.strip():\n                    text_parts.append(paragraph.text)  # noqa: PERF401\n\n            content = \"\\n\".join(text_parts)\n\n            metadata = {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/rag/loaders/docx_loader.py#L35-L71","documentation":"Raised by DOCXLoader._download_from_url() when anything fails while fetching a remote .docx: the safe_get request, raise_for_status(), or writing the response to the temp file. The broad `except Exception` wraps the whole block and re-raises as ValueError with the URL and stringified cause, so network errors, HTTP error statuses, and local tempfile failures all surface through this one message.","triggerScenarios":"DOCXLoader().load(SourceContent('https://example.com/file.docx')) where the URL 404s, the host is unreachable, TLS fails, the request exceeds the 30-second timeout, or the disk is full so tempfile.NamedTemporaryFile raises.","commonSituations":"Expired/pre-signed S3 links; docs portals that return HTML login pages instead of the file (then saved as .docx and rejected later); corporate proxies; URLs from user input that were never validated; read-only temp directories (TMPDIR misconfigured).","solutions":["Fetch the URL manually (curl -I) to confirm it returns 200 with content-type wordprocessingml.document; fix dead or expired links.","If the link is a pre-signed URL, regenerate it closer to load time or download via your storage SDK and pass the local path.","Check TMPDIR is writable and has space if the request itself succeeds.","Retry transient network failures once before giving up."],"exampleFix":"# before\nresult = DOCXLoader().load(SourceContent(signed_url))  # expired link -> ValueError\n\n# after\nimport requests\nr = requests.head(signed_url, timeout=10)\nif r.status_code != 200:\n    signed_url = regenerate_presigned_url(key)\nresult = DOCXLoader().load(SourceContent(signed_url))","handlingStrategy":"retry","validationCode":"import requests\\n\\ndef url_serves_docx(url: str) -> bool:\\n    try:\\n        r = requests.head(url, timeout=10, allow_redirects=True)\\n        return r.ok and 'wordprocessingml' in r.headers.get('Content-Type', '')\\n    except requests.RequestException:\\n        return False","typeGuard":null,"tryCatchPattern":"try:\\n    result = DOCXLoader().load(source)\\nexcept ValueError as e:\\n    if 'Error fetching content' in str(e) and attempts_left():\\n        schedule_retry(source)\\n    else:\\n        raise","preventionTips":["HEAD-check pre-signed URLs right before use; regenerate if stale.","Download with your own session when sites block default agents, then pass the local path.","Ensure TMPDIR is writable in hardened containers."],"tags":["network","http","docx","loader"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}