crewAIInc/crewAI · error · ValueError

Failed to connect to enterprise URL: {e!s}

Error message

Failed to connect to enterprise URL: {e!s}

What it means

Raised when the HTTP request to the enterprise OAuth2 discovery endpoint fails at the transport level — httpx.HTTPError covers connect errors, DNS failures, timeouts (30s limit in the code), and raise_for_status() 4xx/5xx responses. The CLI wraps it into ValueError('Failed to connect to enterprise URL: ...') so the original exception text (e.g. '[Errno -2] Name or service not known' or '401 Unauthorized') is embedded in the message.

Source

Thrown at lib/cli/src/crewai_cli/enterprise/main.py:66

                "X-Crewai-Version": get_crewai_version(),
            }
            response = httpx.get(oauth_endpoint, timeout=30, headers=headers)
            response.raise_for_status()

            try:
                oauth_config = response.json()
            except json.JSONDecodeError as e:
                raise ValueError(f"Invalid JSON response from {oauth_endpoint}") from e

            self._validate_oauth_config(oauth_config)

            console.print(
                "✅ Successfully retrieved OAuth2 configuration", style="green"
            )
            return cast(dict[str, Any], oauth_config)

        except httpx.HTTPError as e:
            raise ValueError(f"Failed to connect to enterprise URL: {e!s}") from e
        except Exception as e:
            raise ValueError(f"Error fetching OAuth2 configuration: {e!s}") from e

    def _update_oauth_settings(
        self, enterprise_url: str, oauth_config: dict[str, Any]
    ) -> None:
        try:
            config_mapping = {
                "enterprise_base_url": enterprise_url,
                "oauth2_provider": oauth_config["provider"],
                "oauth2_audience": oauth_config["audience"],
                "oauth2_client_id": oauth_config["device_authorization_client_id"],
                "oauth2_domain": oauth_config["domain"],
                "oauth2_extra": oauth_config["extra"],
            }

            console.print("🔄 Updating local OAuth2 configuration...")

View on GitHub (pinned to 754d7323be)

Solutions

  1. Verify reachability: curl -v <enterprise_url> from the same machine and network
  2. Fix DNS/VPN: connect to the VPN or correct the hostname before retrying
  3. For self-signed TLS, add the CA to the system trust store (httpx uses certifi/system CAs)
  4. If a 4xx/5xx came back, inspect the status code in the message and fix server-side auth/routing

Example fix

# before
crewai enterprise connect https://crewai.acme.co
# ValueError: Failed to connect to enterprise URL: [Errno -2] Name or service not known
# after (resolve DNS / connect VPN first, verify, then retry)
curl -v https://crewai.acme.co/.well-known/oauth-config
crewai enterprise connect https://crewai.acme.co
Defensive patterns

Strategy: retry

Validate before calling

import httpx

def enterprise_reachable(url: str) -> bool:
    try:
        return httpx.get(url, timeout=30).status_code < 500
    except httpx.HTTPError:
        return False

Try / catch

for attempt in range(3):
    try:
        enterprise_cmd.connect(url)
        break
    except ValueError as e:
        if "Failed to connect" not in str(e) or attempt == 2:
            raise
        time.sleep(2 ** attempt)

Prevention

When it happens

Trigger: `crewai enterprise connect <url>` where the host is unresolvable, the server refuses the connection, a TLS certificate fails verification, the request exceeds the 30-second timeout, or the endpoint returns any non-2xx status (raise_for_status).

Common situations: Typos in the enterprise URL, VPN/internal-host not reachable from the current machine, self-signed certificates without CA trust, firewalls dropping egress, or the enterprise service being down during onboarding.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/09a1765b0bf0b46b. Report an issue: GitHub.