{"record":{"id":"bbb067ffb48ec04d","repo":"D4Vinci/Scrapling","slug":"the-proxy-argument-s-string-is-in-invalid-format","errorCode":null,"errorMessage":"The proxy argument's string is in invalid format!","messagePattern":"The proxy argument's string is in invalid format!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapling/engines/toolbelt/navigation.py","lineNumber":120,"sourceCode":"    :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)\n            return result_dict\n        except ValidationError as e:\n            raise TypeError(f\"Invalid proxy dictionary: {e}\")\n\n    raise TypeError(f\"Invalid proxy string: {proxy_string}\")\n","sourceCodeStart":102,"sourceCodeEnd":131,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/engines/toolbelt/navigation.py#L102-L131","documentation":"Raised inside the `try` block of `construct_proxy_dict` where the parsed proxy pieces are assembled into the Playwright dict. It is the ValueError handler for cases where urllib cannot coerce URL components (classically the port when accessed). In practice this branch is nearly dead code because the f-string assembly rarely raises ValueError, but it exists to convert low-level urllib failures into a clear message about the proxy string format.","triggerScenarios":"Passing a proxy string that parses (valid scheme + hostname) but whose components blow up when formatted, e.g. a malformed port segment such as 'http://proxy:notaport' on Python versions where `proxy.port` access raises, or other degenerate URL component encodings.","commonSituations":"Hand-built proxy URLs with non-numeric ports, unencoded special characters in userinfo, or exotic IPv6/hostname forms that urlparse accepts but cannot fully resolve.","solutions":["Verify the port is numeric: 'http://proxy:8080', not 'http://proxy:80tl'.","URL-encode credentials containing special characters (@, :, /) before embedding them.","Test the URL with `urllib.parse.urlsplit(...).port` in a REPL to confirm every component resolves.","Switch to the dict form {'server': 'http://proxy:8080', 'username': ..., 'password': ...} to bypass string parsing entirely."],"exampleFix":"# before\nproxy = \"http://user:p@ss@proxy:8080\"  # raw '@' breaks parsing\n\n# after\nfrom urllib.parse import quote\nproxy = f\"http://{quote('user', safe='')}:{quote('p@ss', safe='')}@proxy:8080\"","handlingStrategy":"validation","validationCode":"from urllib.parse import urlsplit\n\ndef proxy_components_resolve(p: str) -> bool:\n    try:\n        u = urlsplit(p)\n        _ = u.port, u.hostname, u.username, u.password\n        return u.scheme in (\"http\", \"https\", \"socks4\", \"socks5\") and u.hostname is not None\n    except ValueError:\n        return False","typeGuard":"def is_resolvable_proxy_url(value: object) -> bool:\n    return isinstance(value, str) and proxy_components_resolve(value)","tryCatchPattern":"try:\n    fetcher.fetch(url, proxy=proxy)\nexcept ValueError as e:\n    if \"invalid format\" in str(e):\n        log.warning(\"proxy %r has unresolvable components; url-encode credentials\", proxy)\n    raise","preventionTips":["Quote credentials with urllib.parse.quote before embedding them in the URL.","Keep ports strictly numeric.","Smoke-test proxies with urlsplit(...).port in a REPL before wiring them in."],"tags":["proxy","url-parsing","validation","edge-case"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}