python-cas
raw JSON → 1.7.1 verified Mon Apr 27 auth: no python
Python CAS client library for integrating with CAS (Central Authentication Service) single sign-on servers. Current version 1.7.1, supports Python >=3.10. Release cadence is sporadic.
pip install python-cas Common errors
error ImportError: No module named 'cas' ↓
cause Package not installed.
fix
pip install python-cas
error ModuleNotFoundError: No module named 'casclient' ↓
cause Wrong import path.
fix
Use 'from cas import CASClient' instead.
error python-cas requires Python '>=3.10' but the running Python is 3.8 ↓
cause Using too old Python version.
fix
Upgrade Python to 3.10 or higher, or install an older version of python-cas (e.g., 1.6.0).
error AttributeError: module 'cas' has no attribute 'CASClientV2' ↓
cause Older version of python-cas (<1.1.0) may not have V2.
fix
Upgrade to latest version (>=1.1.0).
Warnings
breaking In v1.7.0, support for Python <3.10 was dropped. Also the dependency on 'six' was removed, which may affect code relying on six. ↓
fix Upgrade to Python >=3.10. Replace any six usage with native Python 3 equivalents.
deprecated CASClientV1 is deprecated and may be removed in a future version. Use CASClient with version=3 instead. ↓
fix Use CASClient with version=2 or 3.
gotcha The 'verify_ssl_certificate' parameter is available since v1.4.0. In older versions SSL verification is always enabled. ↓
fix Upgrade to v1.4.0+ or use requests session with custom verify.
gotcha The client uses requests.Session, which holds cookies. Reuse the client instance for multiple requests to maintain session state. ↓
fix Create one CASClient instance and reuse it.
Imports
- CASClient wrong
from casclient import CASClientcorrectfrom cas import CASClient - CASClientV2
from cas import CASClientV2 - CASClientV3
from cas import CASClientV3
Quickstart
from cas import CASClient
client = CASClient(
version=3,
service_url='https://myapp.example.com/login',
server_url='https://cas.example.com/cas/',
verify_ssl_certificate=True
)
# If you have a ticket from the CAS server:
ticket = request.GET.get('ticket')
if ticket:
user, attributes, pgtiou = client.verify_ticket(ticket)
print(f"Authenticated user: {user}")