From e2df1952dc622fc2936d55f4214fd7a1ec426bcb Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 2 Dec 2023 18:59:38 +0000 Subject: [PATCH] Log JSON responses more usefully --- client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 -- 2.30.2