From 0187a17f72b1abbc23a4cb3b80a85dacc7ac9305 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 6 Jan 2022 16:56:07 -0800 Subject: [PATCH] Limit size of payload in JSONDecodeError --- requests/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index dfbea854f9..5d02589155 100644 --- a/requests/models.py +++ b/requests/models.py @@ -914,7 +914,12 @@ def json(self, **kwargs): if is_py2: # e is a ValueError raise RequestsJSONDecodeError(e.message) else: - raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) + doc = e.doc + if doc: + offset = max(0, e.pos - 2000) + end = min(len(e.doc), e.pos + 2000) + doc = e.doc[offset:end] + raise RequestsJSONDecodeError(e.msg, doc, e.pos) @property def links(self):