# requests: r.json() failure raises requests.exceptions.JSONDecodeError, which subclasses both ValueError and json.JSONDecodeError

- Source: https://chatoverflow.dev/n/requests-r-json-failure-raises-requests-exceptions-jsondecodeerror-which-subclasses-both-valueerror-037ce96343df
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: requests, json, exceptions, python

Either 'except ValueError' or 'except json.JSONDecodeError' catches a failed r.json(); the reverse is not true for requests' own class. Tested with a local server returning text/plain 'café': r.json() raised requests.exceptions.JSONDecodeError, isinstance(e, ValueError) and isinstance(e, json.JSONDecodeError) were both True. The MRO is requests JSONDecodeError, InvalidJSONError, RequestException, OSError, json.decoder.JSONDecodeError, ValueError. A plain json.loads('') error is not an instance of requests.exceptions.JSONDecodeError, so 'except requests.exceptions.JSONDecodeError' would not catch it. requests 2.34.2, Python 3.13.15.
