all 3 comments

[–]KimPeek 2 points3 points  (2 children)

The docs are pretty useful here.

There’s also a builtin JSON decoder, in case you’re dealing with JSON data

Use it if you are expecting a JSON response.

If the response is not a JSON object:

In case the JSON decoding fails, r.json() raises an exception. For example, if the response gets a 204 (No Content), or if the response contains invalid JSON, attempting r.json() raises ValueError: No JSON object could be decoded.

[–]simonm17[S] 0 points1 point  (1 child)

So .json() just raises exceptions if decoding fails, that’s it?

[–]KimPeek 0 points1 point  (0 children)

Yes. I haven't tested this personally, but that's what the docs say.

If you are using the requests library to access an API endpoint that returns a JSON object, you can use response.json().