From 70be0d8911e5a33229828a3236a0cdbeeba381ea Mon Sep 17 00:00:00 2001 From: Luke Lovett Date: Thu, 9 Jul 2015 11:46:20 -0700 Subject: [PATCH] PYTHON-964 - Raise ConnectionFailures properly when connecting to Unix-domain sockets. --- pymongo/pool.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pymongo/pool.py b/pymongo/pool.py index e557ab55a..6434d2e19 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -51,7 +51,11 @@ except ImportError: def _raise_connection_failure(address, error): """Convert a socket.error to ConnectionFailure and raise it.""" host, port = address - msg = '%s:%d: %s' % (host, port, error) + # If connecting to a Unix socket, port will be None. + if port is not None: + msg = '%s:%d: %s' % (host, port, error) + else: + msg = '%s: %s' % (host, error) if isinstance(error, socket.timeout): raise NetworkTimeout(msg) else: