diff --git a/CHANGES.rst b/CHANGES.rst index 964c4205a0..4fb634ab09 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -25,6 +25,9 @@ General (GITHUB-700) [Anthony Shaw] +- Throw a more user-friendly exception on "No address associated with hostname". + [Tomaz Muraus] + Compute ~~~~~~~ diff --git a/libcloud/common/base.py b/libcloud/common/base.py index 0bb26c044f..1321f45e5b 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,24 @@ def request(self, action, params=None, data=None, headers=None, 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 + class_name = self.__class__.__name__ + msg = ('%s. Perhaphs "host" Connection class attribute ' + '(%s.connection) is set to an invalid, non-hostname ' + 'value (%s)?' % + (message, class_name, self.host)) + raise socket.gaierror(msg) + self.reset_context() + raise e except ssl.SSLError: e = sys.exc_info()[1] self.reset_context()