Here are the examples of the python api SoftLayer.exceptions.SoftLayerAPIError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
0
Example 1
def _make_request(self, method, path, **kwargs):
"""Make request. Generally not called directly.
:param method: HTTP Method
:param path: resource Path
:param dict \\*\\*kwargs: extra request arguments
"""
headers = {
'Content-Type': 'application/json',
'User-Agent': consts.USER_AGENT,
}
headers.update(kwargs.get('headers', {}))
kwargs['headers'] = headers
kwargs['auth'] = self.auth
url = '/'.join((self.endpoint, 'v1', self.account_id, path))
resp = requests.request(method, url, **kwargs)
try:
resp.raise_for_status()
except requests.HTTPError as ex:
content = json.loads(ex.response.content)
raise exceptions.SoftLayerAPIError(ex.response.status_code,
content['message'])
return resp
0
Example 2
def __call__(self, request):
"""Makes a SoftLayer API call against the REST endpoint.
This currently only works with GET requests
:param request request: Request object
"""
request.transport_headers.setdefault('Content-Type',
'application/json')
request.transport_headers.setdefault('User-Agent', self.user_agent)
params = request.headers.copy()
if request.mask:
params['objectMask'] = _format_object_mask(request.mask)
if request.limit:
params['limit'] = request.limit
if request.offset:
params['offset'] = request.offset
if request.filter:
params['objectFilter'] = json.dumps(request.filter)
auth = None
if request.transport_user:
auth = requests.auth.HTTPBasicAuth(
request.transport_user,
request.transport_password,
)
method = REST_SPECIAL_METHODS.get(request.method)
is_special_method = True
if method is None:
is_special_method = False
method = 'GET'
body = {}
if request.args:
# NOTE(kmcdonald): force POST when there are arguments because
# the request body is ignored otherwise.
method = 'POST'
body['parameters'] = request.args
raw_body = None
if body:
raw_body = json.dumps(body)
url_parts = [self.endpoint_url, request.service]
if request.identifier is not None:
url_parts.append(str(request.identifier))
# Special methods (createObject, editObject, etc) use the HTTP verb
# to determine the action on the resource
if request.method is not None and not is_special_method:
url_parts.append(request.method)
url = '%s.%s' % ('/'.join(url_parts), 'json')
# Prefer the request setting, if it's not None
verify = request.verify
if verify is None:
verify = self.verify
LOGGER.debug("=== REQUEST ===")
LOGGER.info(url)
LOGGER.debug(request.transport_headers)
LOGGER.debug(raw_body)
try:
resp = requests.request(method, url,
auth=auth,
headers=request.transport_headers,
params=params,
data=raw_body,
timeout=self.timeout,
verify=verify,
cert=request.cert,
proxies=_proxies_dict(self.proxy))
LOGGER.debug("=== RESPONSE ===")
LOGGER.debug(resp.headers)
LOGGER.debug(resp.text)
resp.raise_for_status()
result = json.loads(resp.text)
if isinstance(result, list):
return SoftLayerListResult(
result, int(resp.headers.get('softlayer-total-items', 0)))
else:
return result
except requests.HTTPError as ex:
message = json.loads(ex.response.text)['error']
raise exceptions.SoftLayerAPIError(ex.response.status_code,
message)
except requests.RequestException as ex:
raise exceptions.TransportError(0, str(ex))