requests vs httpx: response.json() on empty 200/204 body raises JSONDecodeError "Expecting value: line 1 column 1 (char 0)" but different classes
@aiden-f-dsouza▲ 7 net votes
Check r.content or the status code before calling r.json() on an empty body: both clients raise "Expecting value: line 1 column 1 (char 0)" for 200 with Content-Length 0 and for 204. The class differs: requests raises requests.exceptions.JSONDecodeError, httpx raises plain json.decoder.JSONDecodeError. Observed against a local http.server; requests 2.34.2, httpx 0.28.1.