From 05f3395b463251f1043f4859c2dcb1c87621ddfa Mon Sep 17 00:00:00 2001 From: Rasmus Thing Date: Fri, 1 Dec 2023 14:47:54 +0100 Subject: [PATCH] Change update response code --- pyfortiztp/models/devices.py | 20 ++++++++++++++------ setup.py | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pyfortiztp/models/devices.py b/pyfortiztp/models/devices.py index e77b2e4..660b943 100644 --- a/pyfortiztp/models/devices.py +++ b/pyfortiztp/models/devices.py @@ -9,7 +9,7 @@ class Devices(FortiZTP): def __init__(self, **kwargs): super(Devices, self).__init__(**kwargs) - def all(self, deviceSN: str=None): + def all(self, deviceSN: str = None): """Retrieves the status of a device. Args: @@ -27,12 +27,17 @@ def all(self, deviceSN: str=None): # Send our request to the API response = requests.get(url, headers={"Authorization": f"Bearer {self.api.access_token}"}, verify=self.api.verify) - + # HTTP 200 OK if response.status_code == 200: return response.json() + else: + try: + return response.json() + except Exception: + return response - def update(self, deviceSN: list, deviceType: str, provisionStatus: str, provisionTarget: str, region: str=None, externalControllerIp: str=None, externalControllerSn: str=None): + def update(self, deviceSN: list, deviceType: str, provisionStatus: str, provisionTarget: str, region: str = None, externalControllerIp: str = None, externalControllerSn: str = None): """Provisions or unprovisions a device. Args: @@ -81,8 +86,11 @@ def update(self, deviceSN: list, deviceType: str, provisionStatus: str, provisio # Send our request to the API response = requests.put(self.api.fortiztp_host + f"/devices", headers={"Authorization": f"Bearer {self.api.access_token}"}, json=devices, verify=self.api.verify) - # API returns 204 No Content on successful request - if response.status_code == 204: + # API returns 200 OK on successful request + if response.status_code == 200: return response.status_code else: - return response.json() \ No newline at end of file + try: + return response.json() + except Exception: + return response diff --git a/setup.py b/setup.py index fba8651..b1c6371 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="pyfortiztp", - version="1.0.0", + version="1.0.1", description="Python API client library for Fortinet's FortiZTP.", long_description=long_description, long_description_content_type="text/markdown",