crewAIInc/crewAI · error · ValueError
URL cannot contain whitespace
Error message
URL cannot contain whitespace
What it means
Pydantic field_validator error from SeleniumScrapingToolSchema when the website_url contains any whitespace character (regex \s match). Unencoded spaces, tabs, or newlines break HTTP navigation and Chrome's URL handling, so the validator rejects them outright instead of letting the driver fail ambiguously. URLs that need spaces must percent-encode them (%20).
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py:46
def validate_website_url(cls, v: str) -> str:
if not v:
raise ValueError("Website URL cannot be empty")
if len(v) > 2048: # Common maximum URL length
raise ValueError("URL is too long (max 2048 characters)")
if not re.match(r"^https?://", v):
raise ValueError("URL must start with http:// or https://")
try:
result = urlparse(v)
if not all([result.scheme, result.netloc]):
raise ValueError("Invalid URL format")
except Exception as e:
raise ValueError(f"Invalid URL: {e!s}") from e
if re.search(r"\s", v):
raise ValueError("URL cannot contain whitespace")
return v
class SeleniumScrapingTool(BaseTool):
name: str = "Read a website content"
description: str = "A tool that can be used to read a website content."
args_schema: type[BaseModel] = SeleniumScrapingToolSchema
website_url: str | None = None
driver: Any | None = None
cookie: dict[str, Any] | None = None
wait_time: int | None = 3
css_element: str | None = None
return_html: bool | None = False
_by: Any | None = None
package_dependencies: list[str] = Field(
default_factory=lambda: ["selenium", "webdriver-manager"]
)View on GitHub (pinned to 754d7323be)
Solutions
- Percent-encode spaces: 'https://example.com/my%20page'.
- Strip/trim the URL before passing it — but note strip() only fixes leading/trailing whitespace, interior whitespace must be encoded.
- Reject or clean whitespace-bearing URLs at ingest time when collecting them from users or files.
Example fix
# before
tool = SeleniumScrapingTool(website_url="https://example.com/my page", css_element="article")
# after
from urllib.parse import quote
clean = "https://example.com/" + quote("my page") # .../my%20page
tool = SeleniumScrapingTool(website_url=clean, css_element="article") Defensive patterns
Strategy: validation
Validate before calling
import re
url = url.strip()
if re.search(r"\s", url):
raise ValueError("URL contains whitespace — encode it (e.g. space -> %20)")
# or auto-fix: url = re.sub(r"\s", "%20", url) Try / catch
from pydantic import ValidationError
try:
tool = SeleniumScrapingTool(website_url=url, css_element=css)
except ValidationError as e:
if "whitespace" in str(e):
import re
tool = SeleniumScrapingTool(website_url=re.sub(r"\s", "%20", url), css_element=css)
else:
raise Prevention
- Trim copied URLs and encode interior spaces as %20.
- Be wary of line-wrapped URLs from chat/email — rejoin before use.
- Apply re.search(r'\s', url) checks wherever URLs enter your system.
When it happens
Trigger: Passing 'https://example.com/my page' (raw space), a URL copied from a wrapped chat/log line that contains a newline, or a trailing/interior tab from spreadsheet/CSV data.
Common situations: Copy-pasting URLs from documents or chat where line-wrapping inserted breaks; CSV/Excel exports with untrimmed cells; LLM agents emitting URLs with literal spaces in the path.
Related errors
- Website URL cannot be empty
- URL is too long (max 2048 characters)
- URL must start with http:// or https://
- Invalid URL format
- Invalid URL: {e!s}
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/9810ee54d2c5d71f.
Report an issue: GitHub.