Skip to content

Commit 13fcec4

Browse files
committed
Fixing AttributeError on some connection errors
1 parent fb53a89 commit 13fcec4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

redis/connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,20 @@ 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()
815820
raise ConnectionError(
816-
f"Error while reading from {self.host}:{self.port}" f" : {e.args}"
821+
f"Error while reading from {hosterr}" f" : {e.args}"
817822
)
818823
except BaseException:
819824
self.disconnect()

0 commit comments

Comments
 (0)