def patch(self, restApi, data={}, silentMode=False, ignoreError=False, maxRetries=5): """ Description A HTTP PATCH function to modify configurations. Parameters restApi: (str): The REST API URL. data: (dict): The data payload for the URL. silentMode: (bool): To display on stdout: URL, data and header info. ignoreError: (bool): True: Don't raise an exception. False: The response will be returned. maxRetries: : The maximum amount of GET retries before declaring as server connection failure. """ retryInterval = 3 restExecutionFailures = 0 while True: if silentMode == False: self.logInfo('\n\tPATCH: {0}\n\tDATA: {1}'.format(restApi, data)) try: response = self._session.request('PATCH', restApi, data=json.dumps(data), headers=self.jsonHeader, allow_redirects=True, verify=self.verifySslCert) if silentMode == False: for redirectStatus in response.history: if '307' in str(response.history): self.logInfo('\t{0}: {1}'.format(redirectStatus, response.url), timestamp=False) self.logInfo('\tSTATUS CODE: %s' % response.status_code, timestamp=False) if ignoreError == False: if not str(response.status_code).startswith('2'): if response.json() and 'errors' in response.json(): errMsg = 'PATCH Exception error: {0}\n'.format(response.json()['errors']) raise IxNetRestApiException('PATCH error: {0}\n'.format(errMsg)) return response except (requests.exceptions.RequestException, Exception) as errMsg: errMsg = 'PATCH Exception error {}/{} retries: {}\n'.format(restExecutionFailures, maxRetries, errMsg) if restExecutionFailures < maxRetries: self.logError(errMsg) restExecutionFailures += 1 time.sleep(retryInterval) continue if restExecutionFailures == maxRetries: raise IxNetRestApiException(errMsg)