Exceptions¶
All library exceptions inherit from MixpanelDataError, enabling callers to catch all library errors with a single except clause.
Explore on DeepWiki
Ask questions about specific exceptions, error recovery patterns, or debugging strategies.
Exception Hierarchy¶
MixpanelDataError
├── ConfigError
│ ├── AccountNotFoundError
│ ├── AccountExistsError
│ ├── AccountInUseError
│ └── ProjectNotFoundError
├── APIError
│ ├── AuthenticationError
│ ├── RateLimitError
│ ├── QueryError
│ ├── ServerError
│ └── JQLSyntaxError
├── OAuthError
└── WorkspaceScopeError
Catching Errors¶
import mixpanel_data as mp
try:
ws = mp.Workspace()
result = ws.segmentation(event="Purchase", from_date="2025-01-01", to_date="2025-01-31")
except mp.AuthenticationError as e:
print(f"Auth failed: {e.message}")
except mp.RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except mp.OAuthError as e:
print(f"OAuth error [{e.code}]: {e.message}")
except mp.WorkspaceScopeError as e:
print(f"Workspace error [{e.code}]: {e.message}")
except mp.AccountInUseError as e:
print(f"Account '{e.account_name}' referenced by targets: {e.referenced_by}")
except mp.MixpanelDataError as e:
print(f"Error [{e.code}]: {e.message}")
Base Exception¶
mixpanel_data.MixpanelDataError
¶
MixpanelDataError(
message: str,
code: str = "UNKNOWN_ERROR",
details: dict[str, Any] | None = None,
)
Bases: Exception
Base exception for all mixpanel_data errors.
All library exceptions inherit from this class, allowing callers to: - Catch all library errors: except MixpanelDataError - Handle specific errors: except AccountNotFoundError - Serialize errors: error.to_dict()
Initialize exception.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
code
|
Machine-readable error code for programmatic handling.
TYPE:
|
details
|
Additional structured data about the error.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
API Exceptions¶
mixpanel_data.APIError
¶
APIError(
message: str,
*,
status_code: int,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
request_body: dict[str, Any] | None = None,
code: str = "API_ERROR",
)
Bases: MixpanelDataError
Base class for Mixpanel API HTTP errors.
Provides structured access to HTTP request/response context for debugging and automated recovery by AI agents. All API-related exceptions inherit from this class, enabling agents to:
- Understand what went wrong (status code, error message)
- See exactly what was sent (request method, URL, params, body)
- See exactly what came back (response body, headers)
- Modify their approach and retry autonomously
Example
Initialize APIError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code from response.
TYPE:
|
response_body
|
Raw response body (string or parsed dict).
TYPE:
|
request_method
|
HTTP method used (GET, POST).
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
request_body
|
Request body sent (for POST requests).
TYPE:
|
code
|
Machine-readable error code.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
response_body
property
¶
Raw response body (string or parsed dict).
mixpanel_data.AuthenticationError
¶
AuthenticationError(
message: str = "Authentication failed",
*,
status_code: int = 401,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
)
Bases: APIError
Authentication with Mixpanel API failed (HTTP 401).
Raised when credentials are invalid, expired, or lack required permissions. Inherits from APIError to provide full request/response context.
Example
Initialize AuthenticationError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code (default 401).
TYPE:
|
response_body
|
Raw response body.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.RateLimitError
¶
RateLimitError(
message: str = "Rate limit exceeded",
*,
retry_after: int | None = None,
status_code: int = 429,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
)
Bases: APIError
Mixpanel API rate limit exceeded (HTTP 429).
Raised when the API returns a 429 status. The retry_after property indicates when the request can be retried. Inherits from APIError to provide full request context for debugging.
Example
Initialize RateLimitError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
retry_after
|
Seconds until retry is allowed (from Retry-After header).
TYPE:
|
status_code
|
HTTP status code (default 429).
TYPE:
|
response_body
|
Raw response body.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.QueryError
¶
QueryError(
message: str = "Query execution failed",
*,
status_code: int = 400,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
request_body: dict[str, Any] | None = None,
)
Bases: APIError
Query execution failed (HTTP 400 or query-specific error).
Raised when an API query fails due to invalid parameters, syntax errors, or other query-specific issues. Inherits from APIError to provide full request/response context for debugging.
Example
Initialize QueryError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code (default 400).
TYPE:
|
response_body
|
Raw response body with error details.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
request_body
|
Request body sent (for POST).
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.ServerError
¶
ServerError(
message: str = "Server error",
*,
status_code: int = 500,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
request_body: dict[str, Any] | None = None,
)
Bases: APIError
Mixpanel server error (HTTP 5xx).
Raised when the Mixpanel API returns a server error. These are typically transient issues that may succeed on retry. The response_body property contains the full error details from Mixpanel, which often include actionable information (e.g., "unit and interval both specified").
Example
Initialize ServerError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code (5xx).
TYPE:
|
response_body
|
Raw response body with error details.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
request_body
|
Request body sent (for POST).
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.JQLSyntaxError
¶
Bases: QueryError
JQL script execution failed with syntax or runtime error (HTTP 412).
Raised when a JQL script fails to execute due to syntax errors, type errors, or other JavaScript runtime issues. Provides structured access to error details from Mixpanel's response.
Inherits from QueryError (and thus APIError) to provide full HTTP context.
Example
Initialize JQLSyntaxError.
| PARAMETER | DESCRIPTION |
|---|---|
raw_error
|
Raw error string from Mixpanel API response.
TYPE:
|
script
|
The JQL script that caused the error.
TYPE:
|
request_path
|
API request path from error response.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
Configuration Exceptions¶
mixpanel_data.ConfigError
¶
Bases: MixpanelDataError
Base for configuration-related errors.
Raised when there's a problem with configuration files, environment variables, or credential resolution.
Initialize ConfigError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
details
|
Additional structured data.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.AccountNotFoundError
¶
Bases: ConfigError
Named account does not exist in configuration.
Raised when attempting to access an account that hasn't been configured. The available_accounts property lists valid account names to help users.
Initialize AccountNotFoundError.
| PARAMETER | DESCRIPTION |
|---|---|
account_name
|
The requested account name that wasn't found.
TYPE:
|
available_accounts
|
List of valid account names for suggestions.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.AccountExistsError
¶
Bases: ConfigError
Account name already exists in configuration.
Raised when attempting to add an account with a name that's already in use.
Initialize AccountExistsError.
| PARAMETER | DESCRIPTION |
|---|---|
account_name
|
The conflicting account name.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.AccountInUseError
¶
Bases: ConfigError
Account is referenced by one or more targets and cannot be removed.
Raised by mp.accounts.remove(name) when the account is referenced by
one or more [targets.NAME] blocks and the caller did not pass
force=True. The list of dependent target names is available in
referenced_by so callers can show a helpful error message or pass
force=True to delete the account and orphan the targets.
Initialize AccountInUseError.
| PARAMETER | DESCRIPTION |
|---|---|
account_name
|
The account that callers tried to remove.
TYPE:
|
referenced_by
|
Names of targets that reference the account.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.ProjectNotFoundError
¶
Bases: ConfigError
Raised when a specified project is not accessible.
Includes the requested project ID and optionally a list of accessible project IDs to help the user correct their selection.
Example
try:
projects = ws.projects()
match = [p for p in projects if p.id == target_id]
if not match:
raise ProjectNotFoundError(
target_id,
available_projects=[p.id for p in projects],
)
except ProjectNotFoundError as e:
print(f"Project '{e.project_id}' not found.")
if e.available_projects:
print(f"Available: {', '.join(e.available_projects)}")
Initialize ProjectNotFoundError.
| PARAMETER | DESCRIPTION |
|---|---|
project_id
|
The requested project ID that wasn't found.
TYPE:
|
available_projects
|
List of accessible project IDs for suggestions.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
OAuth Exceptions¶
Raised during OAuth 2.0 PKCE authentication flows.
| Error Code | Raised When |
|---|---|
OAUTH_TOKEN_ERROR |
Token exchange fails |
OAUTH_REFRESH_ERROR |
Token refresh fails (transient) |
OAUTH_REFRESH_REVOKED |
Refresh token rejected by IdP as invalid_grant (re-run mp account login NAME) |
OAUTH_REGISTRATION_ERROR |
Dynamic client registration fails |
OAUTH_TIMEOUT |
Callback server times out waiting for authorization |
OAUTH_PORT_ERROR |
Cannot bind to a local port for the callback server |
OAUTH_BROWSER_ERROR |
Cannot open the authorization URL in the browser |
mixpanel_data.OAuthError
¶
Bases: MixpanelDataError
OAuth authentication flow error.
Raised for failures during the OAuth 2.0 PKCE flow, including token exchange, token refresh, client registration, callback timeout, port unavailability, and browser launch failures.
Error codes: - OAUTH_TOKEN_ERROR: Token exchange or validation failed - OAUTH_REFRESH_ERROR: Token refresh failed - OAUTH_REGISTRATION_ERROR: Dynamic Client Registration failed - OAUTH_TIMEOUT: Callback server timed out waiting for authorization - OAUTH_PORT_ERROR: All callback ports are occupied - OAUTH_BROWSER_ERROR: Could not open browser for authorization
Example
Initialize OAuthError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
code
|
Machine-readable error code. One of: OAUTH_TOKEN_ERROR, OAUTH_REFRESH_ERROR, OAUTH_REGISTRATION_ERROR, OAUTH_TIMEOUT, OAUTH_PORT_ERROR, OAUTH_BROWSER_ERROR.
TYPE:
|
details
|
Additional structured data about the error.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
Workspace Exceptions¶
Raised when workspace resolution fails for App API endpoints.
| Error Code | Raised When |
|---|---|
NO_WORKSPACES |
No workspaces found for the project |
AMBIGUOUS_WORKSPACE |
Multiple workspaces found and none is marked as default |
WORKSPACE_NOT_FOUND |
Specified workspace ID does not exist |
mixpanel_data.WorkspaceScopeError
¶
WorkspaceScopeError(
message: str,
code: str = "NO_WORKSPACES",
details: dict[str, Any] | None = None,
)
Bases: MixpanelDataError
Workspace resolution error.
Raised when workspace resolution fails during App API requests. This can occur when no workspaces are found, multiple workspaces exist without a clear default, or an explicit workspace ID doesn't match any available workspace.
Error codes: - NO_WORKSPACES: Project has no accessible workspaces - AMBIGUOUS_WORKSPACE: Multiple workspaces, none default; must specify --workspace-id - WORKSPACE_NOT_FOUND: Explicit workspace ID doesn't match any workspace
Example
Initialize WorkspaceScopeError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
code
|
Machine-readable error code. One of: NO_WORKSPACES, AMBIGUOUS_WORKSPACE, WORKSPACE_NOT_FOUND.
TYPE:
|
details
|
Additional structured data about the error.
TYPE:
|