Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
others: Passed on to the requests package.
Raises:
ApiError: If anything other than the expected response code is
returned by the DNA Center API endpoint.
"""
check_type(url, basestring, may_be_none=False)
check_type(params, dict)
# Expected response code
erc = kwargs.pop('erc', EXPECTED_RESPONSE_CODE['PUT'])
response = self.request('PUT', url, erc, 0, params=params,
json=json, data=data, **kwargs)
return extract_and_parse_json(response)
encoded_auth = bytes(encoded_auth, 'utf-8')
# API request
response = requests.post(self._endpoint_url, data=None,
headers={'authorization': b'Basic '
+ encoded_auth},
**self._request_kwargs)
else:
check_type(username, basestring, may_be_none=False)
check_type(password, basestring, may_be_none=False)
# API request
response = requests.post(self._endpoint_url, data=None,
auth=(username, password),
**self._request_kwargs)
check_response_code(response, EXPECTED_RESPONSE_CODE['POST'])
json_data = extract_and_parse_json(response)
# Return a access_token object created from the response JSON data
return self._object_factory('bpm_ac8ae94c4e69a09d', json_data)
headers=headers,
verify=verify,
**kwargs)
if raise_exception:
try:
response.raise_for_status()
except HTTPError as e:
logger.debug(pprint_response_info(e.response))
raise e
logger.debug(pprint_response_info(response))
if original_response:
return response
else:
json_data = extract_and_parse_json(response)
return self._object_factory('bpm_custom', json_data)
if save_file and resp.headers and resp.headers.get('fileName'):
try:
file_name = os.path.join(dirpath,
resp.headers.get('fileName'))
with open(file_name, 'wb') as f:
logger.debug('Downloading {}'.format(file_name))
for chunk in resp.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
except Exception as e:
raise DownloadFailure(resp, e)
logger.debug('Downloaded')
# Needed to create a copy of the raw response
# if not copied it would not recover data and other properties
return HTTPResponse(resp.raw)
return extract_and_parse_json(resp)
return extract_and_parse_json(resp)
erc(int): The expected (success) response code for the request.
others: Passed on to the requests package.
Raises:
ApiError: If anything other than the expected response code is
returned by the DNA Center API endpoint.
"""
check_type(url, basestring, may_be_none=False)
check_type(params, dict)
# Expected response code
erc = kwargs.pop('erc', EXPECTED_RESPONSE_CODE['DELETE'])
response = self.request('DELETE', url, erc, 0, params=params, **kwargs)
return extract_and_parse_json(response)
try:
file_name = os.path.join(dirpath,
resp.headers.get('fileName'))
with open(file_name, 'wb') as f:
logger.debug('Downloading {}'.format(file_name))
for chunk in resp.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
except Exception as e:
raise DownloadFailure(resp, e)
logger.debug('Downloaded')
# Needed to create a copy of the raw response
# if not copied it would not recover data and other properties
return HTTPResponse(resp.raw)
return extract_and_parse_json(resp)
return extract_and_parse_json(resp)
others: Passed on to the requests package.
Raises:
ApiError: If anything other than the expected response code is
returned by the DNA Center API endpoint.
"""
check_type(url, basestring, may_be_none=False)
check_type(params, dict)
# Expected response code
erc = kwargs.pop('erc', EXPECTED_RESPONSE_CODE['POST'])
response = self.request('POST', url, erc, 0, params=params,
json=json, data=data, **kwargs)
return extract_and_parse_json(response)