diff options
author | Konstantin Merenkov <kmerenkov@gmail.com> | 2010-04-02 03:39:56 +0400 |
---|---|---|
committer | Konstantin Merenkov <kmerenkov@gmail.com> | 2010-04-02 03:39:56 +0400 |
commit | 6268781d94d27e86403108c96cf7d687b34f2a7b (patch) | |
tree | f83a18827faca7f3004316ae2d4d8c87504be494 | |
parent | 52e38277b60cc41d3aea2d018ca0aba0693930a5 (diff) | |
download | redis-py-6268781d94d27e86403108c96cf7d687b34f2a7b.tar.gz |
Handling that socket.error's args is either (errno, "msg") or "msg"
-rw-r--r-- | redis/client.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/redis/client.py b/redis/client.py index 27939e3..c159a33 100644 --- a/redis/client.py +++ b/redis/client.py @@ -53,8 +53,12 @@ class Connection(object): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.host, self.port)) except socket.error, e: - raise ConnectionError("Error %s connecting to %s:%s. %s." % \ - (e.args[0], self.host, self.port, e.args[1])) + # args for socket.error can either be (errno, "message") or just "message" + if len(e.args) == 1: + error_message = "Error connecting to %s:%s. %s." % (self.host, self.port, e.args[0]) + else: + error_message = "Error %s connecting %s:%s. %s." % (e.args[0], self.host, self.port, e.args[1]) + raise ConnectionError(error_message) sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) sock.settimeout(self.socket_timeout) self._sock = sock |