From 64ae5709d3fd69c4c102018fc0e2d13e12d4652b Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Mon, 1 Aug 2022 22:22:21 +0100 Subject: [PATCH] serve: Handle TooManySessions on /open --- pywidevine/serve.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pywidevine/serve.py b/pywidevine/serve.py index 9becf70..a358c31 100644 --- a/pywidevine/serve.py +++ b/pywidevine/serve.py @@ -3,6 +3,8 @@ import sys from pathlib import Path from typing import Optional, Union +from pywidevine.exceptions import TooManySessions + try: from aiohttp import web except ImportError: @@ -60,7 +62,14 @@ async def open(request: web.Request) -> web.Response: device = Device.load(request.app["config"]["devices"][device]) cdm = Cdm(device) - session_id = cdm.open() + try: + session_id = cdm.open() + except TooManySessions as e: + return web.json_response({ + "status": 400, + "message": str(e) + }, status=400) + request.app["sessions"][session_id] = cdm return web.json_response({