{"record":{"id":"30ff0411e3d1d2c5","repo":"D4Vinci/Scrapling","slug":"invalid-proxy-string","errorCode":null,"errorMessage":"Invalid proxy string!","messagePattern":"Invalid proxy string!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapling/engines/toolbelt/navigation.py","lineNumber":107,"sourceCode":"            else:\n                await route.continue_()\n        else:\n            await route.continue_()\n\n    return handler\n\n\ndef construct_proxy_dict(proxy_string: str | Dict[str, str] | Tuple) -> Dict:\n    \"\"\"Validate a proxy and return it in the acceptable format for Playwright\n    Reference: https://playwright.dev/python/docs/network#http-proxy\n\n    :param proxy_string: A string or a dictionary representation of the proxy.\n    :return:\n    \"\"\"\n    if isinstance(proxy_string, str):\n        proxy = urlparse(proxy_string)\n        if proxy.scheme not in (\"http\", \"https\", \"socks4\", \"socks5\") or not proxy.hostname:\n            raise ValueError(\"Invalid proxy string!\")\n\n        try:\n            result = {\n                \"server\": f\"{proxy.scheme}://{proxy.hostname}\",\n                \"username\": proxy.username or \"\",\n                \"password\": proxy.password or \"\",\n            }\n            if proxy.port:\n                result[\"server\"] += f\":{proxy.port}\"\n            return result\n        except ValueError:\n            # Urllib will say that one of the parameters above can't be casted to the correct type like `int` for port etc...\n            raise ValueError(\"The proxy argument's string is in invalid format!\")\n\n    elif isinstance(proxy_string, dict):\n        try:\n            validated = convert(proxy_string, ProxyDict)\n            result_dict = structs.asdict(validated)","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/engines/toolbelt/navigation.py#L89-L125","documentation":"Raised by `construct_proxy_dict` in scrapling/engines/toolbelt/navigation.py when a proxy passed as a string cannot be parsed into a usable proxy URL. The string is run through `urlparse`, and if the scheme is not one of http/https/socks4/socks5, or the URL has no hostname, the library rejects it before Playwright ever sees it. This is a config-validation error: the proxy string is structurally invalid, not merely unreachable.","triggerScenarios":"Calling a fetcher (e.g. `Fetcher.get(..., proxy=...)`) or `construct_proxy_dict` directly with strings like `\"proxy1:8080\"` (no scheme), `\"http://\"` (no hostname), `\"ftp://proxy:8080\"` (unsupported scheme), or `\"user:pass@proxy:8080\"` (scheme missing, credentials alone).","commonSituations":"Proxy vendor sends host:port only; users copy proxy strings from dashboards that omit the scheme; using an ftp or other unsupported scheme; typos like `http//proxy:8080`.","solutions":["Prefix the proxy string with an explicit supported scheme, e.g. 'http://proxy1:8080' or 'socks5://proxy1:1080'.","Ensure the string contains a hostname after the scheme (not just credentials or a port).","If the proxy has auth, embed it as 'scheme://user:pass@host:port'.","Alternatively pass a Playwright-style dict {'server': ..., 'username': ..., 'password': ...} which skips string parsing."],"exampleFix":"// before\nproxy = \"proxy1:8080\"\nFetcher.get(url, proxy=proxy)\n\n// after\nproxy = \"http://proxy1:8080\"\nFetcher.get(url, proxy=proxy)","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\n\ndef is_valid_proxy_string(p: str) -> bool:\n    if not isinstance(p, str):\n        return False\n    u = urlparse(p)\n    return u.scheme in (\"http\", \"https\", \"socks4\", \"socks5\") and bool(u.hostname)\n\nproxy = \"proxy1:8080\"\nassert is_valid_proxy_string(proxy), f\"bad proxy: {proxy!r}\"","typeGuard":"def is_proxy_string(value: object) -> bool:\n    return isinstance(value, str) and is_valid_proxy_string(value)","tryCatchPattern":"try:\n    fetcher.fetch(url, proxy=proxy)\nexcept ValueError as e:\n    if \"Invalid proxy string\" in str(e):\n        raise ConfigError(f\"proxy {proxy!r} needs scheme+host, e.g. http://host:port\") from e\n    raise","preventionTips":["Always write proxies as scheme://host[:port]; never host:port alone.","Centralize proxy normalization in one helper so every entry point validates.","Validate the pool once at startup instead of per-request."],"tags":["proxy","validation","playwright","configuration"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}