{"record":{"id":"40eaf399ae73c3bb","repo":"unclecode/crawl4ai","slug":"invalid-proxy-string-format-proxy-str-40eaf3","errorCode":null,"errorMessage":"Invalid proxy string format: {proxy_str}","messagePattern":"Invalid proxy string format: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/proxy_strategy.py","lineNumber":67,"sourceCode":"    def from_string(proxy_str: str) -> \"ProxyConfig\":\n        \"\"\"Create a ProxyConfig from a string in the format 'ip:port:username:password'.\"\"\"\n        parts = proxy_str.split(\":\")\n        if len(parts) == 4:  # ip:port:username:password\n            ip, port, username, password = parts\n            return ProxyConfig(\n                server=f\"http://{ip}:{port}\",\n                username=username,\n                password=password,\n                ip=ip\n            )\n        elif len(parts) == 2:  # ip:port only\n            ip, port = parts\n            return ProxyConfig(\n                server=f\"http://{ip}:{port}\",\n                ip=ip\n            )\n        else:\n            raise ValueError(f\"Invalid proxy string format: {proxy_str}\")\n    \n    @staticmethod\n    def from_dict(proxy_dict: Dict) -> \"ProxyConfig\":\n        \"\"\"Create a ProxyConfig from a dictionary.\"\"\"\n        return ProxyConfig(\n            server=proxy_dict.get(\"server\"),\n            username=proxy_dict.get(\"username\"),\n            password=proxy_dict.get(\"password\"),\n            ip=proxy_dict.get(\"ip\")\n        )\n    \n    @staticmethod\n    def from_env(env_var: str = \"PROXIES\") -> List[\"ProxyConfig\"]:\n        \"\"\"Load proxies from environment variable.\n        \n        Args:\n            env_var: Name of environment variable containing comma-separated proxy strings\n            ","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/proxy_strategy.py#L49-L85","documentation":"ValueError from ProxyConfig.from_string (via the static parser) when the proxy string does not split into the expected number of colon-separated parts. The parser accepts 'ip:port', 'user:pass@ip:port', and 'user:pass@ip:port:extra' shapes; any other part count (0, 1, 4+) is rejected with this message.","triggerScenarios":"Passing a malformed proxy string such as 'http://1.2.3.4:8080' (scheme prefix adds parts), '1.2.3.4' (no port), 'a:b:c:d:e' (too many), or one containing stray colons in the password when using more parts than supported.","commonSituations":"Copy-pasting a proxy URL with an http:// scheme from a provider dashboard, environment-variable proxy strings from third-party services, passwords containing colons, or IPv6 addresses (multiple colons) breaking the naive split.","solutions":["Strip the scheme: use '1.2.3.4:8080' or 'user:pass@1.2.3.4:8080' — no 'http://' prefix (the parser adds it).","For passwords containing colons, URL-encode the password (%3A) or use ProxyConfig.from_dict / construct ProxyConfig directly with server/username/password fields.","For IPv6 proxies, construct ProxyConfig directly instead of the string parser.","Validate the string with a quick split test before feeding it to the crawler config."],"exampleFix":"# before\nproxy = ProxyConfig.from_string(\"http://user:pass@1.2.3.4:8080\")  # ValueError: Invalid proxy string format\n\n# after\nproxy = ProxyConfig.from_string(\"user:pass@1.2.3.4:8080\")\n# or, for messy credentials:\nproxy = ProxyConfig.from_dict({\"server\": \"http://1.2.3.4:8080\", \"username\": \"user\", \"password\": \"p:a:s:s\"})","handlingStrategy":"validation","validationCode":"def valid_proxy_string(s: str) -> bool:\n    import re\n    # schemeless user:pass@host:port or host:port, IPv4 only\n    return bool(re.fullmatch(r\"(?:[\\w.%+-]+:[\\w.%+-]+@)?\\d{1,3}(?:\\.\\d{1,3}){3}:\\d{1,5}\", s))","typeGuard":null,"tryCatchPattern":"try:\n    proxy = ProxyConfig.from_string(raw_proxy)\nexcept ValueError as e:\n    if 'Invalid proxy string' in str(e):\n        proxy = ProxyConfig.from_dict({\"server\": f\"http://{parsed_host}:{parsed_port}\", \"username\": u, \"password\": p})","preventionTips":["Never include the http:// scheme in from_string inputs — the parser prepends it.","URL-encode credentials containing ':' or '@' (%3A, %40).","For IPv6 or exotic credentials, build ProxyConfig via from_dict instead of string parsing.","Validate proxy strings at config load time with the regex above."],"tags":["proxy","configuration","validation","parsing"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}