Skip to content
Myr

Merge pull request #5777 from cclauss/patch-1

Before adoption: this commit came in with the history the project adopted, so no landing records it.

quickstart.rst: r.json() can raise JSONDecodeError on Py3

authored by Ian Stapleton Cordasco · committed by GitHub · parents 913880c, f79d1ef · Browse files · 2 files+9 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−2 removed

  • other:+9 added−2 removed

2 files+9 added−2 removed

modified:docs/user/quickstart.rst+3 added-1 removed
148 unmodified lines
149 [{'repository': {'open_issues': 0, 'url': 'https://github.com/...150151In case the JSON decoding fails, ``r.json()`` raises an exception. For example, if152the response gets a 204 (No Content), or if the response contains invalid JSON,153attempting ``r.json()`` raises ``ValueError: No JSON object could be decoded``.153attempting ``r.json()`` raises ``simplejson.JSONDecodeError`` if simplejson is154installed or raises ``ValueError: No JSON object could be decoded`` on Python 2 or155``json.JSONDecodeError`` on Python 3.156157It should be noted that the success of the call to ``r.json()`` does **not**158indicate the success of the response. Some servers may return a JSON object in a159failed response (e.g. error details with HTTP 500). Such JSON will be decoded
407 unmodified lines
modified:requests/models.py+6 added-1 removed
875 unmodified lines
876 def json(self, **kwargs):877 r"""Returns the json-encoded content of a response, if any.878879 :param \*\*kwargs: Optional arguments that ``json.loads`` takes.880 :raises simplejson.JSONDecodeError: If the response body does not881 contain valid json and simplejson is installed.882 :raises json.JSONDecodeError: If the response body does not contain883 valid json and simplejson is not installed on Python 3.880 :raises ValueError: If the response body does not contain valid json.884 :raises ValueError: If the response body does not contain valid885 json and simplejson is not installed on Python 2. 886 """887888 if not self.encoding and self.content and len(self.content) > 3:889 # No encoding set. JSON RFC 4627 section 3 states we should expect
72 unmodified lines