From 28d09862c170613638b494bb90b724005cd6ce31 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 13 Apr 2025 18:07:22 -0700 Subject: [PATCH] more safe dict --- app.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index b45bf3d..0dabe51 100644 --- a/app.py +++ b/app.py @@ -19,8 +19,15 @@ def safe_dict(obj): return [safe_dict(i) for i in obj] elif isinstance(obj, bytes): return obj.decode(errors="replace") + elif hasattr(obj, "__dict__"): + return safe_dict(vars(obj)) # Recursively process custom objects + elif hasattr(obj, "to_dict"): + return safe_dict(obj.to_dict()) # If object has a to_dict() method else: - return obj + try: + return str(obj) # Fallback + except Exception: + return None @app.route("/") def index():