We wrote the Python (3.8) code below, which uses KalturaApiClient version 17.18.0. The ‘expiry’ value we set is 900000.
Our Kaltura API sessions often succeed, and they sometimes fail with “Error ‘-1, INVALID_STR’ (INVALID_KS).” In regard to the ‘expiry’ value, I have assumed that a KS session would expire after N seconds, where N is the value of ‘expiry’ but that seems untrue. The average duration of our successful Kaltura API sessions are longer than the average duration of our failed Kaltura API sessions.
Two questions:
- What is expected of the ‘expiry’ value? Is it seconds-since-Epoch or seconds-from-now or something else?
- What does “Error ‘-1, INVALID_STR’ (INVALID_KS)” tell us?
expiry = app.config['KALTURA_EXPIRY']
partner_id = app.config['KALTURA_PARTNER_ID']
self.client = KalturaClient(KalturaConfiguration())
result = self.client.session.startWidgetSession(
expiry=expiry,
widgetId=f'_{partner_id}',
)
self.client.setKs(result.ks)
token_hash = hashlib.sha256((result.ks + app.config['KALTURA_APP_TOKEN']).encode('ascii')).hexdigest()
result = self.client.appToken.startSession(
expiry=expiry,
id=app.config['KALTURA_APP_TOKEN_ID'],
tokenHash=token_hash,
type=KalturaSessionType.ADMIN,
)
self.client.setKs(result.ks)