|
23 | 23 | cookiejar_from_dict, morsel_to_cookie)
|
24 | 24 | from requests.exceptions import (
|
25 | 25 | ConnectionError, ConnectTimeout, InvalidSchema, InvalidURL,
|
26 |
| - MissingSchema, ReadTimeout, Timeout, RetryError, TooManyRedirects, |
| 26 | + MissingSchema, ReadTimeout, Timeout, RetryError, RequestException, TooManyRedirects, |
27 | 27 | ProxyError, InvalidHeader, UnrewindableBodyError, SSLError, InvalidProxyURL, InvalidJSONError)
|
28 | 28 | from requests.models import PreparedRequest
|
29 | 29 | from requests.structures import CaseInsensitiveDict
|
30 | 30 | from requests.sessions import SessionRedirectMixin
|
31 | 31 | from requests.models import urlencode
|
32 | 32 | from requests.hooks import default_hooks
|
33 |
| -from requests.compat import MutableMapping |
| 33 | +from requests.compat import JSONDecodeError, is_py3, MutableMapping |
34 | 34 |
|
35 | 35 | from .compat import StringIO, u
|
36 | 36 | from .utils import override_environ
|
@@ -2585,5 +2585,15 @@ def test_post_json_nan(self, httpbin):
|
2585 | 2585 |
|
2586 | 2586 | def test_json_decode_compatibility(self, httpbin):
|
2587 | 2587 | r = requests.get(httpbin('bytes/20'))
|
2588 |
| - with pytest.raises(requests.exceptions.JSONDecodeError): |
| 2588 | + with pytest.raises(requests.exceptions.JSONDecodeError) as excinfo: |
2589 | 2589 | r.json()
|
| 2590 | + assert isinstance(excinfo.value, RequestException) |
| 2591 | + assert isinstance(excinfo.value, JSONDecodeError) |
| 2592 | + assert r.text not in str(excinfo.value) |
| 2593 | + |
| 2594 | + @pytest.mark.skipif(not is_py3, reason="doc attribute is only present on py3") |
| 2595 | + def test_json_decode_persists_doc_attr(self, httpbin): |
| 2596 | + r = requests.get(httpbin('bytes/20')) |
| 2597 | + with pytest.raises(requests.exceptions.JSONDecodeError) as excinfo: |
| 2598 | + r.json() |
| 2599 | + assert excinfo.value.doc == r.text |
0 commit comments