question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

response.json() raises inconsistent exception type

See original GitHub issue

There are some comments about this on https://github.com/psf/requests/issues/4842 but I think it warrants its own issue.

If simplejson is present in the environment, the library uses it so .json() returns simplejson.errors.JSONDecodeError rather than json.decoder.JSONDecodeError

If I’m writing a library that uses requests I don’t know what other libraries will be present in an environment. I expect that a method returns a consistent exception type that I can handle. As it stands, anyone writing a library (e.g. https://github.com/conda-forge/conda-smithy/pull/1369, https://github.com/Vonage/vonage-python-sdk/issues/197) has to check themselves if simplejson is present to know what exception type will be thrown.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
rowanseymourcommented, Apr 16, 2021

Maybe the simplest solution which wouldn’t break existing code is to provide a requests.JSONDecodeError which aliases whatever exception type will be thrown, and calling code should always use that.

0reactions
steveberdycommented, Jul 3, 2021

@sigmavirus24 I can make that edit in my second branch. I didn’t do any try/except for importing the JSONDecodeError from simplejson or json, so I’ll do that and then I’ll submit a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python request JSON intermittent Type Error - Stack Overflow
JSONDecodeError: print('response was not a JSON string, but', ... It does not necessarily mean that r.json() is not a valid JSON.
Read more >
18 SQL/JSON Function JSON_VALUE - Oracle Help Center
If json_value targets a JSON object, and you specify a user-defined SQL object type as the return type, then json_value returns an instance...
Read more >
An Exploration of JSON Interoperability Vulnerabilities
JSON INTEROPERABILITY SECURITY RISKS · 1. Inconsistent Duplicate Key Precedence · 2. Key Collision: Character Truncation and Comments · 3. JSON ...
Read more >
Troubleshooting Amazon CloudSearch - AWS Documentation
First, make sure that the batch is valid XML or JSON. If it is, check for invalid document IDs and make sure you...
Read more >
How to use the requests.exceptions.HTTPError function ... - Snyk
HTTPError as exc: logger.exception(exc) if response.json()['error_code'] ... request_object.raise_for_status() except HTTPError as e: # raise detailed error ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found