Repository: libcloud
Updated Branches:
  refs/heads/trunk 64f4329c3 -> 19d6a4611


Throw a more user-friendly error on "No address associated with hostname"
exception.

This could simply indicate Connection.host attribute being set to an invalid
value.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/3fb45e2a
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/3fb45e2a
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/3fb45e2a

Branch: refs/heads/trunk
Commit: 3fb45e2ac74b97fa1cee391573f62529c136c68e
Parents: 64f4329
Author: Tomaz Muraus <[email protected]>
Authored: Tue Feb 23 10:52:57 2016 +0100
Committer: Tomaz Muraus <[email protected]>
Committed: Tue Feb 23 10:53:30 2016 +0100

----------------------------------------------------------------------
 libcloud/common/base.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/3fb45e2a/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 0bb26c0..9b0d6b9 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -16,6 +16,7 @@
 import os
 import sys
 import ssl
+import socket
 import copy
 import binascii
 import time
@@ -818,6 +819,22 @@ class Connection(object):
                 else:
                     self.connection.request(method=method, url=url, body=data,
                                             headers=headers)
+        except socket.gaierror:
+            e = sys.exc_info()[1]
+            message = str(e)
+            errno = getattr(e, 'errno', None)
+
+            if errno == -5:
+                # Throw a more-friendly exception on "no address associated
+                # with hostname" error. This error could simpli indicate that
+                # "host" Connection class attribute is set to an incorrect
+                # value
+                msg = ('%s. Perhaphs "host" Connection class attribute (%s) '
+                       'is set to an invalid, non-hostname value?' %
+                       (message, self.host))
+                raise socket.gaierror(msg)
+            self.reset_context()
+            raise e
         except ssl.SSLError:
             e = sys.exc_info()[1]
             self.reset_context()

Reply via email to