BerriAI/litellm · error · Exception
Error listing files in '{directory_path}': {e}
Error message
Error listing files in '{directory_path}': {e} What it means
Raised by BitBucketClient.list_files_in_directory when the failure is not an HTTP response error at all — the exception has no .response attribute. Typical causes are network-layer failures (DNS resolution, connection refused, TLS errors) or bugs inside response.json() parsing (JSONDecodeError). It is the non-HTTP branch of the error handler, so the message wraps the raw exception string.
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 6c2dcb801b)
Solutions
- Test connectivity from the same host/container: curl -v https://api.bitbucket.org/2.0/workspaces
- Set HTTPS_PROXY/HTTP_PROXY if the environment requires an egress proxy
- Add retry with backoff for transient connection errors since this path has no automatic retry
- If the message mentions JSON, inspect whether a proxy is returning an HTML error page instead of the BitBucket API
Example fix
# before
files = client.list_files_in_directory("prompts")
# after (guard transient network failures)
from requests.exceptions import ConnectionError as RequestsConnectionError
try:
files = client.list_files_in_directory("prompts")
except Exception as e:
if isinstance(e.__context__, RequestsConnectionError):
logger.warning("BitBucket unreachable, using cached prompt list")
files = cached_files
else:
raise Defensive patterns
Strategy: retry
Validate before calling
import socket
def bitbucket_reachable(host: str = "api.bitbucket.org", timeout: float = 3.0) -> bool:
try:
socket.getaddrinfo(host, 443)
return True
except socket.gaierror:
return False Try / catch
try:
files = client.list_files_in_directory("prompts")
except Exception as e:
if hasattr(e, "response") or hasattr(getattr(e, "__context__", None), "response"):
raise # HTTP-level error, see error 341
logger.warning("Network-level BitBucket failure: %s", e)
files = cached_listing # degrade gracefully Prevention
- Configure HTTPS_PROXY in corporate networks before deploying
- Add DNS/egress health checks for api.bitbucket.org to your deployment probes
- Keep a last-known-good listing on disk for degraded-mode operation
When it happens
Trigger: The https_handler.get() call raising requests.exceptions.ConnectionError / DNSError before any response arrives, a proxy or firewall blocking api.bitbucket.org from the LiteLLM proxy pod, or a response body that is not valid JSON when the code parses pagination values.
Common situations: Running LiteLLM proxy in a container with no egress to api.bitbucket.org, corporate proxy environments where HTTPS_PROXY is unset, DNS misconfiguration in Kubernetes, or transient network drops during prompt sync.
Related errors
- Error getting file metadata for '{file_path}': {e}
- Error fetching file '{file_path}': {e}
- Mavvrik FOCUS destination: GCS session init missing Location
- APIConnectionError: {exception_provider} - {error_str}
- DNS resolution failed for '{hostname}': {e}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/7959d86c84ac9fed.
Report an issue: GitHub.