def invoke_api(ip, command, logger, headers=None):
if headers is None:
headers = {}
try:
method = command.get_method()
url = "https://{0}:9000{1}".format(ip, command.get_url())
data = jsonpickle.encode(command, unpicklable=False)
if "get" == method.lower():
response = requests.get(url=url, headers=headers, verify=False)
else:
headers["Content-Type"] = "application/json"
response = requests.request(method=method, data=str(data), url=url, headers=headers, verify=False)
json_obj = validate_response(response)
return command.process_response(json_obj)
except Exception as e:
logger.error("Failed to execute command: %s", e)
return None
评论列表
文章目录