Skip to content

Exceptions

All psxdata exceptions inherit from PSXDataError.

Custom exception hierarchy for psxdata.

All library exceptions inherit from PSXDataError, allowing callers to catch any library error with a single except clause.

PSXDataError

Bases: Exception

Base exception for all psxdata library errors.

Source code in psxdata/exceptions.py
class PSXDataError(Exception):
    """Base exception for all psxdata library errors."""

PSXUnavailableError

Bases: PSXDataError

PSX server is unreachable or returned a 5xx response.

Source code in psxdata/exceptions.py
class PSXUnavailableError(PSXDataError):
    """PSX server is unreachable or returned a 5xx response."""

PSXConnectionError

Bases: PSXUnavailableError

Network-level failure — DNS resolution failed, connection refused, or timeout.

The server was never reached.

Source code in psxdata/exceptions.py
class PSXConnectionError(PSXUnavailableError):
    """Network-level failure — DNS resolution failed, connection refused, or timeout.

    The server was never reached.
    """

PSXServerError

Bases: PSXUnavailableError

PSX server was reached but returned a 5xx HTTP response.

Source code in psxdata/exceptions.py
class PSXServerError(PSXUnavailableError):
    """PSX server was reached but returned a 5xx HTTP response."""

PSXAuthError

Bases: PSXDataError

PSX returned 401 or 403 — authentication or authorisation failure.

Source code in psxdata/exceptions.py
class PSXAuthError(PSXDataError):
    """PSX returned 401 or 403 — authentication or authorisation failure."""

PSXRateLimitError

Bases: PSXDataError

PSX returned 429 — rate limit exceeded.

Source code in psxdata/exceptions.py
class PSXRateLimitError(PSXDataError):
    """PSX returned 429 — rate limit exceeded."""

PSXParseError

Bases: PSXDataError

HTML structure changed or response could not be parsed.

Also raised for unexpected 4xx responses (400, 404, etc.).

Source code in psxdata/exceptions.py
class PSXParseError(PSXDataError):
    """HTML structure changed or response could not be parsed.

    Also raised for unexpected 4xx responses (400, 404, etc.).
    """

InvalidSymbolError

Bases: PSXDataError

The requested ticker symbol does not exist on PSX.

Source code in psxdata/exceptions.py
class InvalidSymbolError(PSXDataError):
    """The requested ticker symbol does not exist on PSX."""

DelistedSymbolError

Bases: InvalidSymbolError

The requested ticker existed on PSX but has since been delisted.

Source code in psxdata/exceptions.py
class DelistedSymbolError(InvalidSymbolError):
    """The requested ticker existed on PSX but has since been delisted."""

DataNotAvailableError

Bases: PSXDataError

Valid symbol requested but PSX returned no data for the given period.

Source code in psxdata/exceptions.py
class DataNotAvailableError(PSXDataError):
    """Valid symbol requested but PSX returned no data for the given period."""

CacheError

Bases: PSXDataError

Disk cache read or write failure.

Source code in psxdata/exceptions.py
class CacheError(PSXDataError):
    """Disk cache read or write failure."""

Catching exceptions

from psxdata.exceptions import PSXConnectionError, PSXServerError
import psxdata

try:
    df = psxdata.stocks("ENGRO")
except PSXConnectionError:
    print("Network error — PSX unreachable. Check your connection.")
except PSXServerError:
    print("PSX server error — try again later.")