Exceptions
CPAU API Exception Classes
This module defines custom exceptions for the CPAU API library.
- exception cpau.exceptions.CpauError[source]
Bases:
ExceptionBase exception for all CPAU API errors.
- exception cpau.exceptions.CpauConnectionError[source]
Bases:
CpauErrorRaised when unable to connect to CPAU portal.
- exception cpau.exceptions.CpauAuthenticationError[source]
Bases:
CpauErrorRaised when authentication fails.
- exception cpau.exceptions.CpauMeterNotFoundError[source]
Bases:
CpauErrorRaised when specified meter is not found.
Exception Hierarchy
All CPAU-specific exceptions inherit from CpauError:
CpauError
├── CpauAuthenticationError
├── CpauConnectionError
├── CpauApiError
└── CpauMeterNotFoundError
Exception Classes
CpauError
CpauAuthenticationError
CpauConnectionError
CpauApiError
CpauMeterNotFoundError
Example Usage
from cpau import CpauApiSession
from cpau.exceptions import (
CpauAuthenticationError,
CpauConnectionError,
CpauApiError
)
from datetime import date
try:
with CpauApiSession(userid='user@example.com', password='wrong') as session:
meter = session.get_electric_meter()
data = meter.get_usage('daily', date(2024, 12, 1))
except CpauAuthenticationError as e:
print(f"Login failed: {e}")
print("Check your credentials in secrets.json")
except CpauConnectionError as e:
print(f"Connection failed: {e}")
print("Check your network connection")
except CpauApiError as e:
print(f"API error: {e}")
print("The CPAU portal may have changed or be unavailable")