Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Make the HTTP request to the API endpoint
try:
logger.debug('Attempt {}'.format(c))
logger.debug(pprint_request_info(abs_url, method,
_headers=self.headers,
**kwargs))
response = self._req_session.request(method, abs_url, **kwargs)
except socket.error:
# A socket error
try:
c += 1
logger.debug('Attempt {}'.format(c))
response = self._req_session.request(method, abs_url,
**kwargs)
except Exception as e:
raise dnacentersdkException('Socket error {}'.format(e))
except IOError as e:
if e.errno == errno.EPIPE:
# EPIPE error
try:
c += 1
logger.debug('Attempt {}'.format(c))
response = self._req_session.request(method, abs_url,
**kwargs)
except Exception as e:
raise dnacentersdkException('PipeError {}'.format(e))
else:
raise dnacentersdkException('IOError {}'.format(e))
try:
# Check the response code for error conditions
check_response_code(response, erc)
except RateLimitError as e:
from builtins import *
import requests
from .response_codes import RESPONSE_CODES
logger = logging.getLogger(__name__)
class dnacentersdkException(Exception):
"""Base class for all dnacentersdk package exceptions."""
pass
class AccessTokenError(dnacentersdkException):
"""Raised when an incorrect DNA Center Access Token has been provided."""
pass
class VersionError(dnacentersdkException):
"""Raised when an incorrect DNA Center version has been provided."""
pass
class DownloadFailure(dnacentersdkException):
"""Errors returned in response to requests sent to the DNA Center APIs
with stream=True.
Several data attributes are available for inspection.
"""
def __init__(self, response, exception):
def __init__(self, response):
assert isinstance(response, requests.Response)
# Extended warning attributes
self.retry_after = max(1, int(response.headers.get('Retry-After', 15)))
"""The `Retry-After` time period (in seconds) provided by DNA Center.
Defaults to 15 seconds if the response `Retry-After` header isn't
present in the response headers, and defaults to a minimum wait time of
1 second if DNA Center returns a `Retry-After` header of 0 seconds.
"""
super(RateLimitWarning, self).__init__()
class MalformedRequest(dnacentersdkException):
"""Raised when a malformed request is received from DNA Center user."""
pass
class dnacentersdkException(Exception):
"""Base class for all dnacentersdk package exceptions."""
pass
class AccessTokenError(dnacentersdkException):
"""Raised when an incorrect DNA Center Access Token has been provided."""
pass
class VersionError(dnacentersdkException):
"""Raised when an incorrect DNA Center version has been provided."""
pass
class DownloadFailure(dnacentersdkException):
"""Errors returned in response to requests sent to the DNA Center APIs
with stream=True.
Several data attributes are available for inspection.
"""
def __init__(self, response, exception):
assert isinstance(response, requests.Response)
assert isinstance(exception, Exception)
# Extended exception attributes
self.response = response
"""The :class:`requests.Response` object returned from the API call."""
self.request = self.response.request
"""The :class:`requests.PreparedRequest` of the API call."""
logger = logging.getLogger(__name__)
class dnacentersdkException(Exception):
"""Base class for all dnacentersdk package exceptions."""
pass
class AccessTokenError(dnacentersdkException):
"""Raised when an incorrect DNA Center Access Token has been provided."""
pass
class VersionError(dnacentersdkException):
"""Raised when an incorrect DNA Center version has been provided."""
pass
class DownloadFailure(dnacentersdkException):
"""Errors returned in response to requests sent to the DNA Center APIs
with stream=True.
Several data attributes are available for inspection.
"""
def __init__(self, response, exception):
assert isinstance(response, requests.Response)
assert isinstance(exception, Exception)
# Extended exception attributes
self.response = response
"[{status_code}]{status} - {message} : {original_error}".format(
status_code=self.status_code,
status=" " + self.status if self.status else "",
message=self.message,
original_error=self.original_error,
)
)
def __repr__(self):
return "<{exception_name} [{status_code}]>".format(
exception_name=self.__class__.__name__,
status_code=self.status_code,
)
class ApiError(dnacentersdkException):
"""Errors returned in response to requests sent to the DNA Center APIs.
Several data attributes are available for inspection.
"""
def __init__(self, response):
assert isinstance(response, requests.Response)
# Extended exception attributes
self.response = response
"""The :class:`requests.Response` object returned from the API call."""
self.request = self.response.request
"""The :class:`requests.PreparedRequest` of the API call."""
self.status_code = self.response.status_code