diff --git a/py-json/LANforge/lfcli_base.py b/py-json/LANforge/lfcli_base.py index 6309b434..fa45a3d9 100644 --- a/py-json/LANforge/lfcli_base.py +++ b/py-json/LANforge/lfcli_base.py @@ -4,7 +4,8 @@ from pprint import pprint import LANforge.LFUtils from LANforge.LFUtils import * - +import traceback +from traceback import extract_stack class LFCliBase: # do not use `super(LFCLiBase,self).__init__(self, host, port, _debugOn) @@ -17,13 +18,22 @@ class LFCliBase: self.mgr_url = "http://%s:%s/" % (self.lfjson_host, self.lfjson_port) def jsonPost(self, _req_url, _data): - lf_r = LFRequest.LFRequest(self.mgr_url + _req_url) - _data['suppress_preexec_cli'] = True - _data['suppress_preexec_method'] = True - lf_r.addPostData(_data) - if (self.debugOn): - LANforge.LFUtils.debug_printer.pprint(_data) - json_response = lf_r.jsonPost(self.debugOn) + json_response = None + if self.mgr_url.endswith('/') and _req_url.startswith('/'): + _req_url = _req_url[1:] + try: + lf_r = LFRequest.LFRequest(self.mgr_url + _req_url) + _data['suppress_preexec_cli'] = True + _data['suppress_preexec_method'] = True + lf_r.addPostData(_data) + if (self.debugOn): + LANforge.LFUtils.debug_printer.pprint(_data) + json_response = lf_r.jsonPost(self.debugOn) + except Exception as x: + print(f"jsonPost posted to {_req_url}") + pprint(_data) + print(x.__traceback__) + # Debugging # if (json_response != None): # print("jsonReq: response: ") @@ -31,8 +41,18 @@ class LFCliBase: return json_response def jsonGet(self, _req_url): - lf_r = LFRequest.LFRequest(self.mgr_url + _req_url) - json_response = lf_r.getAsJson(self.debugOn) + json_response = None + if self.mgr_url.endswith('/') and _req_url.startswith('/'): + _req_url = _req_url[1:] + try: + lf_r = LFRequest.LFRequest(self.mgr_url + _req_url) + json_response = lf_r.getAsJson(self.debugOn) + if (json_response is None) and self.debugOn: + raise ValueError(json_response) + except ValueError as ve: + print("jsonGet asked for "+_req_url) + print(ve.__traceback__) + return json_response def checkConnect(self):