Exceptions
Every error raised by psxdata inherits fromPSXDataError, so you can write a single catch-all handler regardless of what goes wrong:
Exception hierarchy
PSXDataError
Exception.
Catch PSXDataError when you want a single handler that covers every failure the library can raise. All exceptions listed below are subclasses of this class.
Raised by: every public function in psxdata under error conditions.
PSXUnavailableError
PSXConnectionError and PSXServerError. Catch this class when you want to handle all availability failures with a single branch, without distinguishing between a network error and a server error.
Raised by: all functions that make HTTP requests — stocks(), quote(), tickers(), indices(), sectors(), symbols(), fundamentals(), debt_market(), eligible_scrips().
PSXConnectionError
- No internet connectivity
- DNS resolution failure for
dps.psx.com.pk - Connection timeout (server not responding within the request timeout)
- Connection refused
PSXServerError
PSXAuthError
PSXRateLimitError
cache=True (the default) where possible.
PSXParseError
tickers(index=...) and indices() when passed an invalid index name.
InvalidSymbolError
DelistedSymbolError is a subclass of this exception, so catching InvalidSymbolError also catches delisted tickers.
Raised by: functions that fetch per-symbol data, most commonly stocks().
DelistedSymbolError
InvalidSymbolError, catching InvalidSymbolError is sufficient if you do not need to distinguish between a never-listed symbol and a delisted one.
Raised by: functions that fetch per-symbol data when a symbol is recognised as a former PSX listing.
DataNotAvailableError
InvalidSymbolError: the ticker is real, but no data exists for the given time range.
CacheError
cache=True (the default) and the cache directory is inaccessible, the cache is corrupted, or disk space is exhausted.
To recover, you can pass cache=False to bypass the cache, or delete the cache directory (default: ~/.psxdata/cache/) and let it be recreated on the next call.