def post(self, restApi, data={}, headers=None, silentMode=False, ignoreError=False): """ Description A HTTP POST function to mainly used to create or start operations. Parameters restApi: The REST API URL. data: The data payload for the URL. headers: The special header to use for the URL. silentMode: True or False. To display URL, data and header info. noDataJsonDumps: True or False. If True, use json dumps. Else, accept the data as-is. ignoreError: True or False. If False, the response will be returned. No exception will be raised. """ if headers != None: originalJsonHeader = self.jsonHeader self.jsonHeader = headers data = json.dumps(data) if silentMode == False: self.logInfo('\n\tPOST: {0}\n\tDATA: {1}\n\tHEADERS: {2}'.format(restApi, data, self.jsonHeader)) try: response = requests.post(restApi, data=data, headers=self.jsonHeader, verify=self.verifySsl) # 200 or 201 if silentMode == False: self.logInfo('\tSTATUS CODE: %s' % response.status_code, timestamp=False) if not str(response.status_code).startswith('2'): if ignoreError == False: raise IxLoadRestApiException('http POST error: {0}\n'.format(response.text)) # Change it back to the original json header if headers != None: self.jsonHeader = originalJsonHeader return response except requests.exceptions.RequestException as errMsg: raise IxLoadRestApiException('http POST error: {0}\n'.format(errMsg))