crewAIInc/crewAI · error · ValueError
Error fetching content from URL {url}: {e!s}
Error message
Error fetching content from URL {url}: {e!s} What it means
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.
Source
Thrown at lib/crewai-tools/src/crewai_tools/rag/loaders/docx_loader.py:53
def _download_from_url(url: str, kwargs: dict[str, Any]) -> str:
headers = kwargs.get(
"headers",
{
"Accept": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"User-Agent": "Mozilla/5.0 (compatible; crewai-tools DOCXLoader)",
},
)
try:
response = safe_get(url, headers=headers, timeout=30)
response.raise_for_status()
# Create temporary file to save the DOCX content
with tempfile.NamedTemporaryFile(suffix=".docx", delete=False) as temp_file:
temp_file.write(response.content)
return temp_file.name
except Exception as e:
raise ValueError(f"Error fetching content from URL {url}: {e!s}") from e
def _load_from_file(
self,
file_path: str,
source_ref: str,
DocxDocument: Any, # noqa: N803
) -> LoaderResult:
try:
doc = DocxDocument(file_path)
text_parts = []
for paragraph in doc.paragraphs:
if paragraph.text.strip():
text_parts.append(paragraph.text) # noqa: PERF401
content = "\n".join(text_parts)
metadata = {View on GitHub (pinned to 754d7323be)
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.
Example fix
# before
result = DOCXLoader().load(SourceContent(signed_url)) # expired link -> ValueError
# after
import requests
r = requests.head(signed_url, timeout=10)
if r.status_code != 200:
signed_url = regenerate_presigned_url(key)
result = DOCXLoader().load(SourceContent(signed_url)) Defensive patterns
Strategy: retry
Validate before calling
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 Try / catch
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
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Unable to fetch documentation from {docs_url}: {e}
- Failed to download PDF from {url}: {e!s}
- python-docx is required for DOCX loading. Install with: 'uv
- Source must be a valid file path or URL, got: {source_conten
- Error loading DOCX file: {e!s}
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/b4a16949a47a1f17.
Report an issue: GitHub.