Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ General
(GITHUB-700)
[Anthony Shaw]

- Throw a more user-friendly exception on "No address associated with hostname".
[Tomaz Muraus]

Compute
~~~~~~~

Expand Down
19 changes: 19 additions & 0 deletions libcloud/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import sys
import ssl
import socket
import copy
import binascii
import time
Expand Down Expand Up @@ -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 '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's too late now, but you meant 'perhaps'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps :P

Joking aside, good catch, will push a fix.

'(%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()
Expand Down