BerriAI/litellm · error · Exception

Error fetching file '{file_path}': {e}

Error message

Error fetching file '{file_path}': {e}

What it means

The non-HTTP branch of get_file's error handling: the caught exception had no .response attribute (or .response lacked status_code), so it was not an HTTP-layer error from the HTTPHandler. The exception is wrapped in a generic Exception with the file path. Typical sources are DNS resolution failures, connection refused/timeout, TLS errors, or bugs in response processing — i.e. the request likely never reached BitBucket or failed below HTTP.

Source

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

                    return base64.b64decode(response.content).decode("utf-8")
                except Exception:
                    return response.text

        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 None
                elif e.response.status_code == 403:
                    raise Exception(
                        f"Access denied to file '{file_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 fetch file '{file_path}': {e}")
            else:
                raise Exception(f"Error fetching file '{file_path}': {e}")

    def list_files(self, directory_path: str = "", file_extension: str = ".prompt") -> list[str]:
        """
        List files in a directory with a specific extension.

        Args:
            directory_path: Directory path in the repository (empty for root)
            file_extension: File extension to filter by (default: .prompt)

        Returns:
            List of file paths
        """
        safe_dir: Final = _sanitize_file_path(directory_path) if directory_path else ""
        url: Final = f"{self.base_url}/repositories/{self.workspace}/{self.repository}/src/{self.branch}/{safe_dir}"

        try:
            response: Final = self.http_handler.get(url, headers=self.headers)
            response.raise_for_status()

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the embedded '{e}' text — DNS/connect/SSL errors name the actual failure
  2. Verify egress: curl https://api.bitbucket.org/2.0 from the same container/pod
  3. Set HTTPS_PROXY/HTTP_PROXY (and pass them into the deployment) if a corporate proxy is required
  4. If base_url was overridden, revert to https://api.bitbucket.org/2.0 or fix the typo

Example fix

# before
# pod has no egress -> Exception: Error fetching file 'prompts/x.prompt': [Errno -2] Name or service not known

# after
# allow egress / set proxy in the container spec
env:
  - name: HTTPS_PROXY
    value: http://proxy.corp.example:3128
Defensive patterns

Strategy: try-catch

Validate before calling

import socket

def can_resolve_bitbucket() -> bool:
    try:
        socket.getaddrinfo("api.bitbucket.org", 443)
        return True
    except socket.gaierror:
        return False

assert can_resolve_bitbucket(), "no DNS egress to api.bitbucket.org"

Try / catch

try:
    content = client.get_file(path)
except Exception as e:
    msg = str(e).lower()
    if any(k in msg for k in ("name or service not known", "connect", "ssl", "proxy")):
        raise NetworkError("cannot reach api.bitbucket.org — check egress/proxy config") from e
    raise

Prevention

When it happens

Trigger: No network egress from the container (DNS failure for api.bitbucket.org); corporate proxy required but httpx handler not configured to use it; TLS certificate interception breaking the handshake; self.base_url customized to an unreachable value.

Common situations: Running litellm in an air-gapped or egress-restricted cluster; proxy env vars (HTTPS_PROXY) not passed into the container; base_url typo introduced when overriding the default https://api.bitbucket.org/2.0.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/cc4731c261e79254. Report an issue: GitHub.