diff --git a/conductor/conductor.py b/conductor/conductor.py index dd05c17..7b8acbc 100644 --- a/conductor/conductor.py +++ b/conductor/conductor.py @@ -34,7 +34,7 @@ class BaseClient(object): self.baseResource = baseResource def get(self, resPath, queryParams=None, timeout=(5, 10)): - theUrl = "{}/{}".format(self.baseURL, resPath) + theUrl = "{}/{}".format(self.baseURL, resPath.strip("/")) resp = requests.get(theUrl, params=queryParams, headers=self.headers, timeout=timeout) self.__checkForSuccess(resp) if(resp.content == b''): @@ -43,12 +43,13 @@ class BaseClient(object): return resp.json() def post(self, resPath, queryParams, body, headers=None, timeout=(5, 10)): - theUrl = "{}/{}".format(self.baseURL, resPath.lstrip("/")) + theUrl = "{}/{}".format(self.baseURL, resPath.strip("/")) theHeader = self.headers if headers is not None: theHeader = self.mergeTwoDicts(self.headers, headers) if body is not None: jsonBody = json.dumps(body, ensure_ascii=True) + print(theUrl, queryParams, theHeader, jsonBody) resp = requests.post(theUrl, params=queryParams, data=jsonBody, headers=theHeader, timeout=timeout) else: resp = requests.post(theUrl, params=queryParams, headers=theHeaders, timeout=timeout) @@ -57,7 +58,7 @@ class BaseClient(object): return self.__return(resp, theHeader) def put(self, resPath, queryParams=None, body=None, headers=None, timeout=(5, 10)): - theUrl = "{}/{}".format(self.baseURL, resPath.lstrip("/")) + theUrl = "{}/{}".format(self.baseURL, resPath.strip("/")) theHeader = self.headers if headers is not None: theHeader = self.mergeTwoDicts(self.headers, headers) @@ -72,7 +73,7 @@ class BaseClient(object): self.__checkForSuccess(resp) def delete(self, resPath, queryParams, timeout=(5, 10)): - theUrl = "{}/{}".format(self.baseURL, resPath.lstrip("/")) + theUrl = "{}/{}".format(self.baseURL, resPath.strip("/")) resp = requests.delete(theUrl, params=queryParams, headers=self.headers, timeout=timeout) self.__print(resp) self.__checkForSuccess(resp) @@ -182,7 +183,7 @@ class TaskClient(BaseClient): def updateTask(self, taskObj): url = self.makeUrl('') - headers = {'Accept': 'text/plain; encodingcharset=utf-8'} + headers = {'Content-Type':'application/json', 'Accept': 'text/plain; encodingcharset=utf-8'} self.post(url, None, taskObj, headers) def pollForTask(self, taskType, workerid, domain=None, extraParams=None, reRegisterFunction=None): @@ -196,7 +197,7 @@ class TaskClient(BaseClient): params = dict(list(extraParams.items()) + list(params.items())) try: logging.getLogger("pyexec").debug("Polling at %s with %s", url, params) - return self.get(url, params, timeout=(1, 3)) + return self.get(url, params) except requests.HTTPError as err: if reRegisterFunction is not None: reRegisterFunction()