from Cookie import Morsel
from StringIO import StringIO
from .packages.urllib3.packages.ordered_dict import OrderedDict
- from httplib import IncompleteRead
builtin_str = str
bytes = str
from http.cookies import Morsel
from io import StringIO
from collections import OrderedDict
- from http.client import IncompleteRead
builtin_str = str
str = str
import collections
import datetime
-import socket
from io import BytesIO, UnsupportedOperation
from .hooks import default_hooks
from .packages.urllib3.fields import RequestField
from .packages.urllib3.filepost import encode_multipart_formdata
from .packages.urllib3.util import parse_url
-from .packages.urllib3.exceptions import DecodeError
+from .packages.urllib3.exceptions import (
+ DecodeError, ReadTimeoutError, ProtocolError)
from .exceptions import (
HTTPError, RequestException, MissingSchema, InvalidURL,
ChunkedEncodingError, ContentDecodingError, ConnectionError)
iter_slices, guess_json_utf, super_len, to_native_string)
from .compat import (
cookielib, urlunparse, urlsplit, urlencode, str, bytes, StringIO,
- is_py2, chardet, json, builtin_str, basestring, IncompleteRead)
+ is_py2, chardet, json, builtin_str, basestring)
from .status_codes import codes
#: The set of HTTP status codes that indicate an automatically
try:
for chunk in self.raw.stream(chunk_size, decode_content=True):
yield chunk
- except IncompleteRead as e:
+ except ProtocolError as e:
raise ChunkedEncodingError(e)
except DecodeError as e:
raise ContentDecodingError(e)
- except socket.error as e:
+ except ReadTimeoutError as e:
raise ConnectionError(e)
except AttributeError:
# Standard file-like object.
assert next(iter(r))
io.close()
- def test_iter_content_handles_socket_error(self):
- r = requests.Response()
- import socket
-
- class RawMock(object):
- def stream(self, chunk_size, decode_content=None):
- raise socket.error()
-
- r.raw = RawMock()
- with pytest.raises(ConnectionError):
- list(r.iter_content())
-
def test_response_decode_unicode(self):
"""
When called with decode_unicode, Response.iter_content should always