Skip to content

Commit

Permalink
Limit size of payload in JSONDecodeError
Browse files Browse the repository at this point in the history
  • Loading branch information
cHYzZQo committed Jan 7, 2022
1 parent 620ed4f commit 0187a17
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion requests/models.py
Expand Up @@ -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):
Expand Down

0 comments on commit 0187a17

Please sign in to comment.