From: Simon Tatham Date: Sat, 2 Dec 2023 18:59:38 +0000 (+0000) Subject: Log JSON responses more usefully X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=e2df1952dc622fc2936d55f4214fd7a1ec426bcb;p=mastodonochrome.git Log JSON responses more usefully --- diff --git a/client.py b/client.py index e83f42f..3e55434 100644 --- a/client.py +++ b/client.py @@ -1,4 +1,5 @@ import calendar +import json import os import re import requests @@ -51,7 +52,13 @@ class Client: pr(" Response headers:") for k, v in rsp.headers.items(): pr(f" {k}: {v}") - pr(f" Response: {rsp.content!r}") + if 'application/json' not in rsp.headers.get('content-type'): + pr(f" Response: {rsp.content!r}") + else: + pr(" Response JSON:") + j = rsp.json() + for line in json.dumps(j, indent=4).splitlines(): + pr(" " + line) self.log_response = log_response