{"record":{"id":"9810ee54d2c5d71f","repo":"crewAIInc/crewAI","slug":"url-cannot-contain-whitespace","errorCode":null,"errorMessage":"URL cannot contain whitespace","messagePattern":"URL cannot contain whitespace","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py","lineNumber":46,"sourceCode":"    def validate_website_url(cls, v: str) -> str:\n        if not v:\n            raise ValueError(\"Website URL cannot be empty\")\n\n        if len(v) > 2048:  # Common maximum URL length\n            raise ValueError(\"URL is too long (max 2048 characters)\")\n\n        if not re.match(r\"^https?://\", v):\n            raise ValueError(\"URL must start with http:// or https://\")\n\n        try:\n            result = urlparse(v)\n            if not all([result.scheme, result.netloc]):\n                raise ValueError(\"Invalid URL format\")\n        except Exception as e:\n            raise ValueError(f\"Invalid URL: {e!s}\") from e\n\n        if re.search(r\"\\s\", v):\n            raise ValueError(\"URL cannot contain whitespace\")\n\n        return v\n\n\nclass SeleniumScrapingTool(BaseTool):\n    name: str = \"Read a website content\"\n    description: str = \"A tool that can be used to read a website content.\"\n    args_schema: type[BaseModel] = SeleniumScrapingToolSchema\n    website_url: str | None = None\n    driver: Any | None = None\n    cookie: dict[str, Any] | None = None\n    wait_time: int | None = 3\n    css_element: str | None = None\n    return_html: bool | None = False\n    _by: Any | None = None\n    package_dependencies: list[str] = Field(\n        default_factory=lambda: [\"selenium\", \"webdriver-manager\"]\n    )","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py#L28-L64","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\ntool = SeleniumScrapingTool(website_url=\"https://example.com/my page\", css_element=\"article\")\n\n# after\nfrom urllib.parse import quote\nclean = \"https://example.com/\" + quote(\"my page\")  # .../my%20page\ntool = SeleniumScrapingTool(website_url=clean, css_element=\"article\")","handlingStrategy":"validation","validationCode":"import re\n\nurl = url.strip()\nif re.search(r\"\\s\", url):\n    raise ValueError(\"URL contains whitespace — encode it (e.g. space -> %20)\")\n# or auto-fix: url = re.sub(r\"\\s\", \"%20\", url)","typeGuard":null,"tryCatchPattern":"from pydantic import ValidationError\n\ntry:\n    tool = SeleniumScrapingTool(website_url=url, css_element=css)\nexcept ValidationError as e:\n    if \"whitespace\" in str(e):\n        import re\n        tool = SeleniumScrapingTool(website_url=re.sub(r\"\\s\", \"%20\", url), css_element=css)\n    else:\n        raise","preventionTips":["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."],"tags":["validation","url","selenium","whitespace","encoding"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}