You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2020/10/04 15:39:28 UTC
[libcloud] 09/14: Throw a more user-friendly exception if invalid
region is passed to the Ovh driver constructor.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit 7b6dd90e363117c18c2e6ec17180f28042e6bd02
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Sun Oct 4 17:10:33 2020 +0200
Throw a more user-friendly exception if invalid region is passed to the
Ovh driver constructor.
---
libcloud/common/ovh.py | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libcloud/common/ovh.py b/libcloud/common/ovh.py
index 2e1ba76..822395d 100644
--- a/libcloud/common/ovh.py
+++ b/libcloud/common/ovh.py
@@ -23,6 +23,8 @@ try:
except ImportError:
import json # type: ignore
+import requests
+
from libcloud.utils.py3 import httplib
from libcloud.utils.connection import get_response_object
from libcloud.common.types import InvalidCredsError
@@ -132,8 +134,17 @@ class OvhConnection(ConnectionUserAndKey):
'X-Ovh-Application': user_id,
}
httpcon = LibcloudConnection(host=self.host, port=443)
- httpcon.request(method='POST', url=action, body=data, headers=headers)
- response = JsonResponse(httpcon.getresponse(), httpcon)
+
+ try:
+ httpcon.request(method='POST', url=action, body=data, headers=headers)
+ except requests.exceptions.ConnectionError as e:
+ if 'name or service not known' in str(e).lower():
+ raise ValueError('Received "name or service not known" error '
+ 'when requesting consumer key. This likely '
+ 'indicates invalid region argument was'
+ 'passed to the driver constructor.'
+ 'Used host: %s. Original error: %s' %
+ (self.host, str(e)))
if response.status == httplib.UNAUTHORIZED:
raise InvalidCredsError()