{"record":{"id":"61fe9233c899e0b5","repo":"NousResearch/hermes-agent","slug":"malformed-proxy-environment-variable-key-value","errorCode":null,"errorMessage":"Malformed proxy environment variable {key}={value!r}. Fix or unset your proxy settings and try again.","messagePattern":"Malformed proxy environment variable (.+?)=(.+?)\\. Fix or unset your proxy settings and try again\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/auxiliary_client.py","lineNumber":3531,"sourceCode":"    which concatenates 'export' into the port number.  Without this\n    check the OpenAI/httpx client raises a cryptic ``Invalid port``\n    error that doesn't name the offending env var.\n    \"\"\"\n    from urllib.parse import urlparse\n\n    normalize_proxy_env_vars()\n\n    for key in (\"HTTPS_PROXY\", \"HTTP_PROXY\", \"ALL_PROXY\",\n                \"https_proxy\", \"http_proxy\", \"all_proxy\"):\n        value = str(os.environ.get(key) or \"\").strip()\n        if not value:\n            continue\n        try:\n            parsed = urlparse(value)\n            if parsed.scheme:\n                _ = parsed.port          # raises ValueError for e.g. '6153export'\n        except ValueError as exc:\n            raise RuntimeError(\n                f\"Malformed proxy environment variable {key}={value!r}. \"\n                \"Fix or unset your proxy settings and try again.\"\n            ) from exc\n\n\ndef _validate_base_url(base_url: str) -> None:\n    \"\"\"Reject obviously broken custom endpoint URLs before they reach httpx.\"\"\"\n    from urllib.parse import urlparse\n\n    candidate = str(base_url or \"\").strip()\n    if not candidate or candidate.startswith(\"acp://\"):\n        return\n    try:\n        parsed = urlparse(candidate)\n        if parsed.scheme in {\"http\", \"https\"}:\n            _ = parsed.port              # raises ValueError for malformed ports\n    except ValueError as exc:\n        raise RuntimeError(","sourceCodeStart":3513,"sourceCodeEnd":3549,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/agent/auxiliary_client.py#L3513-L3549","documentation":"Pre-flight proxy validation: for each of HTTPS_PROXY/HTTP_PROXY/ALL_PROXY (and lowercase variants), urlparse(value).port raises ValueError for garbage such as 'http://127.0.0.1:6153export'. Hermes rejects malformed proxy values up front — with the offending variable named — instead of letting httpx fail later with an opaque error.","triggerScenarios":"Any of the six proxy env vars set to a value whose port component is unparseable (e.g. digits glued to 'export', scheme with no colon, or truncated host:port) before an auxiliary HTTP client is constructed.","commonSituations":"Shell quoting accident appending text to the port ('6153export'); CI injecting malformed proxy variables; proxy-switcher utilities writing bad values into the environment.","solutions":["Fix the value to a valid URL form: export HTTPS_PROXY='http://127.0.0.1:6153'","Unset the broken variable if no proxy is actually needed","Audit shell rc files and CI environment definitions for the typo'd export","Verify the fix parses: python -c \"from urllib.parse import urlparse; print(urlparse('http://127.0.0.1:6153').port)\""],"exampleFix":"# before\nexport HTTPS_PROXY=http://127.0.0.1:6153export\n\n# after\nexport HTTPS_PROXY=http://127.0.0.1:6153","handlingStrategy":"validation","validationCode":"import os\nfrom urllib.parse import urlparse\n\ndef proxy_env_valid() -> str | None:\n    for key in (\"HTTPS_PROXY\", \"HTTP_PROXY\", \"ALL_PROXY\",\n                \"https_proxy\", \"http_proxy\", \"all_proxy\"):\n        value = str(os.environ.get(key) or \"\").strip()\n        if not value:\n            continue\n        try:\n            parsed = urlparse(value)\n            if parsed.scheme:\n                _ = parsed.port\n        except ValueError:\n            return f\"{key}={value!r}\"\n    return None\n\nbad = proxy_env_valid()\nif bad:\n    raise SystemExit(f\"Fix malformed proxy variable {bad} before starting\")","typeGuard":null,"tryCatchPattern":"try:\n    build_auxiliary_client()\nexcept RuntimeError as e:\n    if \"Malformed proxy environment variable\" in str(e):\n        unset_or_fix_proxy_from_message(str(e))  # message names the offending key/value\n        build_auxiliary_client()\n    else:\n        raise","preventionTips":["Quote proxy exports in shell rc files: export HTTPS_PROXY='http://host:port'","Validate proxy env vars in CI pipeline preflight before jobs that make HTTP calls","After changing proxy tools, re-parse each proxy URL before launching long-running processes"],"tags":["proxy","environment","validation","http"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}