commit f877c9f13e5f669032ca8800bcd1d6495d8daca9
parent c866e05d213c6f13a1e433a2cdb5424c608d00e5
Author: Brian C. Lane <bcl@brianlane.com>
Date: Sun, 20 Mar 2022 10:01:04 -0700
api: Default to string in json output
This allows use of datetime objects in the details dict to be output
without converting them to strings.
Diffstat:
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/strix/api.py b/src/strix/api.py
@@ -23,7 +23,8 @@ import os
import mimetypes
mimetypes.add_type("video/mp4", ".m4v")
-from bottle import route, run, static_file, request, Response
+from bottle import install, route, run, static_file, request, Response, JSONPlugin
+from json import dumps
from . import logger
from .events import camera_events
@@ -69,4 +70,6 @@ def run_api(logging_queue: mp.Queue, base_dir: str, host: str, port: int, debug:
"limit": limit,
"events": events}
+ # Use str as default in json dumps for objects like datetime
+ install(JSONPlugin(json_dumps=lambda s: dumps(s, default=str)))
run(host=host, port=port, debug=debug, server="gevent")