diff --git a/requests/models.py b/requests/models.py
index 0dc55568..f1726a1c 100644
@@ -9,7 +9,7 @@ This module contains the primary objects that power Requests.
import collections
import datetime
-
+import socket
from io import BytesIO, UnsupportedOperation
from .hooks import default_hooks
from .structures import CaseInsensitiveDict
@@ -21,8 +21,9 @@ from .packages.urllib3.filepost import encode_multipart_formdata
from .packages.urllib3.util import parse_url
from .packages.urllib3.exceptions import DecodeError
from .exceptions import (
- HTTPError, RequestException, MissingSchema, InvalidURL,
- ChunkedEncodingError, ContentDecodingError)
+ ChunkedEncodingError, ContentDecodingError, ConnectionError,
+ HTTPError, MissingSchema, RequestException, InvalidURL
+)
from .utils import (
guess_filename, get_auth_from_url, requote_uri,
stream_decode_response_unicode, to_key_val_list, parse_header_links,
@@ -640,6 +641,8 @@ class Response(object):
raise ChunkedEncodingError(e)
except DecodeError as e:
raise ContentDecodingError(e)
+ except socket.error as e:
+ raise ConnectionError(e)
except AttributeError:
# Standard file-like object.
while True:
@@ -647,8 +650,8 @@ class Response(object):
if not chunk:
break
yield chunk
-
- self._content_consumed = True
+ finally:
+ self._content_consumed = True
# simulate reading small chunks of the content
reused_chunks = iter_slices(self._content, chunk_size)
@@ -810,4 +813,4 @@ class Response(object):
*Note: Should not normally need to be called explicitly.*
"""
- return self.raw.release_conn()
+ return self.raw.release_conn()
\ No newline at end of file