From 14a3ee14563d5d198a0800dd60a7e31ff85aea91 Mon Sep 17 00:00:00 2001 From: disqualifier Date: Mon, 29 Jun 2026 21:34:37 -0400 Subject: [PATCH] fix: AW-2 json() returns None on a non-UTF-8 body instead of raising MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit responses.json() catches UnicodeDecodeError alongside JSONDecodeError — text() can raise it on a non-UTF-8 payload, which is a 'not valid JSON' outcome per the docstring, not an error to propagate. Signed-off-by: disqualifier --- src/aioweb/responses.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aioweb/responses.py b/src/aioweb/responses.py index 697598b..53f8bd1 100644 --- a/src/aioweb/responses.py +++ b/src/aioweb/responses.py @@ -92,7 +92,9 @@ class Response: """parsed JSON content, or None if not valid JSON""" try: return _json.loads(self.text()) - except _json.JSONDecodeError: + except (_json.JSONDecodeError, UnicodeDecodeError): + # text() decodes the body and can raise UnicodeDecodeError on a non-UTF-8 + # payload — that's a "not valid JSON" outcome, not an error to propagate return None def raise_for_status(self):