BerriAI/litellm · error · Exception

Error listing files in

Error message

Error listing files in '{directory_path}': {e}

What it means

Raised by BitBucketClient.list_files when the GET to /repositories/{workspace}/{repository}/src/{branch}/{directory} fails with an exception that carries no HTTP status code, i.e. the request never produced an HTTP response. The sibling branches handle 404 (returns []), 403, 401, and other HTTP status errors, so this else-branch catches connection-level failures and response-decoding failures. The original exception text is appended to the message.

Solutions

  1. From the same host, curl the exact URL to confirm reachability: curl -H "Authorization: Bearer $TOKEN" "https://api.bitbucket.org/2.0/repositories/<ws>/<repo>/src/main/"
  2. Verify the base_url in the BitBucket config dict (default https://api.bitbucket.org/2.0) and fix typos in host/port
  3. Check proxy env vars and CA bundles (HTTPS_PROXY, SSL_CERT_FILE, REQUESTS_CA_BUNDLE) if running behind a corporate proxy
  4. Add retry/backoff around prompt-manager initialization for transient network failures

Example fix

// before
files = bitbucket_client.list_files("prompts")

// after
import time
for attempt in range(3):
    try:
        files = bitbucket_client.list_files("prompts")
        break
    except Exception as e:
        if attempt == 2 or not str(e).startswith("Error listing files"):
            raise
        time.sleep(2 ** attempt)
Defensive patterns

Strategy: try-catch

Validate before calling

import httpx, os

def bitbucket_reachable(base_url: str = "https://api.bitbucket.org/2.0",
                        token: str | None = None) -> bool:
    token = token or os.getenv("BITBUCKET_ACCESS_TOKEN", "")
    try:
        httpx.get(base_url, headers={"Authorization": f"Bearer {token}"}, timeout=5.0)
        return True
    except httpx.RequestError:
        return False

Try / catch

try:
    files = client.list_files(directory)
except Exception as e:
    msg = str(e)
    if msg.startswith("Access denied"):
        ...  # permission problem
    elif msg.startswith("Authentication failed"):
        ...  # credential problem
    elif msg.startswith("Error listing files"):
        ...  # network-level failure: check DNS/proxy/TLS, retry with backoff
    else:
        raise

Prevention

When it happens

Trigger: Calling list_files (directly, or via the BitBucket prompt manager loading all .prompt files at startup) when DNS for api.bitbucket.org fails, the TCP connection is refused or times out (firewall/proxy blocking egress), TLS verification fails (corporate SSL inspection, missing CA bundle), or response.json() raises because a proxy returned an HTML error page instead of JSON. Also triggered by a custom base_url pointing at a wrong host/port.

Common situations: Corporate networks with SSL-inspecting proxies, misconfigured HTTP_PROXY/HTTPS_PROXY env vars, self-hosted BitBucket Data Center URL typos in the client config dict, transient outages while the LiteLLM proxy boots, and IPv6 resolution problems in containers.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/7959d86c84ac9fed. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/bitbucket/bitbucket_client.py:163

                        files.append(file_path)

            return files

        except Exception as e:
            # Check if it's an HTTP error
            if hasattr(e, "response") and hasattr(e.response, "status_code"):
                if e.response.status_code == 404:
                    return []
                elif e.response.status_code == 403:
                    raise Exception(
                        f"Access denied to directory '{directory_path}'. Check your BitBucket permissions for workspace '{self.workspace}' and repository '{self.repository}'."
                    )
                elif e.response.status_code == 401:
                    raise Exception("Authentication failed. Check your BitBucket access token and permissions.")
                else:
                    raise Exception(f"Failed to list files in '{directory_path}': {e}")
            else:
                raise Exception(f"Error listing files in '{directory_path}': {e}")

    def get_repository_info(self) -> dict[str, Any]:
        """
        Get information about the repository.

        Returns:
            Dictionary containing repository information
        """
        url: Final = f"{self.base_url}/repositories/{self.workspace}/{self.repository}"

        try:
            response: Final = self.http_handler.get(url, headers=self.headers)
            response.raise_for_status()
            return response.json()
        except Exception as e:
            raise Exception(f"Failed to get repository info: {e}")

    def test_connection(self) -> bool:

View on GitHub (pinned to 77b7c6c40c)