Skip to content

Commit 26491dc

Browse files
authored
Fixing AttributeError on some connection errors (#1905)
1 parent fb53a89 commit 26491dc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

redis/connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,16 +805,19 @@ def can_read(self, timeout=0):
805805

806806
def read_response(self, disable_decoding=False):
807807
"""Read the response from a previously sent command"""
808+
try:
809+
hosterr = f"{self.host}:{self.port}"
810+
except AttributeError:
811+
hosterr = "connection"
812+
808813
try:
809814
response = self._parser.read_response(disable_decoding=disable_decoding)
810815
except socket.timeout:
811816
self.disconnect()
812-
raise TimeoutError(f"Timeout reading from {self.host}:{self.port}")
817+
raise TimeoutError(f"Timeout reading from {hosterr}")
813818
except OSError as e:
814819
self.disconnect()
815-
raise ConnectionError(
816-
f"Error while reading from {self.host}:{self.port}" f" : {e.args}"
817-
)
820+
raise ConnectionError(f"Error while reading from {hosterr}" f" : {e.args}")
818821
except BaseException:
819822
self.disconnect()
820823
raise

0 commit comments

Comments
 (0)