From 71059a4430068224bd4028f4117f4255a2d069b6 Mon Sep 17 00:00:00 2001 From: Brian Berry Date: Mon, 22 May 2023 13:11:30 -0400 Subject: [PATCH 1/5] Adds nexus_headers to Nexus class. Contains rate-limiting and other headers from the most recent Nexus API call --- pynxm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pynxm.py b/pynxm.py index b949883..9bf2dd8 100644 --- a/pynxm.py +++ b/pynxm.py @@ -65,6 +65,7 @@ def __init__(self, api_key): "content-type": "application/json", } ) + self.nexus_headers = None @classmethod def sso(cls, app_slug, sso_token, sso_id=None): @@ -103,6 +104,7 @@ def _make_request(self, operation, endpoint, payload=None, data=None, headers=No timeout=30, ) status_code = response.status_code + self.nexus_headers = {k: v for k, v in response.headers.items() if "X-" in k} if status_code not in (200, 201): if status_code == 429: raise LimitReachedError( From 08416ccf8f764f26120b2002cdec27c35166caa7 Mon Sep 17 00:00:00 2001 From: Brian Berry Date: Fri, 26 May 2023 20:35:04 -0400 Subject: [PATCH 2/5] Handles 50x better? --- pynxm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pynxm.py b/pynxm.py index 9bf2dd8..59b0658 100644 --- a/pynxm.py +++ b/pynxm.py @@ -111,6 +111,8 @@ def _make_request(self, operation, endpoint, payload=None, data=None, headers=No "You have reached your request limit. " "Please wait one hour before trying again." ) + elif status_code in (503, 504): + raise RequestError("Status Code {} - {}".format(status_code, response.reason)) else: try: msg = response.json()["message"] From c78975818023f99422f05a4fd9c4117ac602e049 Mon Sep 17 00:00:00 2001 From: Brian Berry Date: Sat, 23 Mar 2024 15:35:33 -0400 Subject: [PATCH 3/5] Sets nexus_headers to default empty dict --- pynxm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynxm.py b/pynxm.py index 59b0658..7e2e760 100644 --- a/pynxm.py +++ b/pynxm.py @@ -65,7 +65,7 @@ def __init__(self, api_key): "content-type": "application/json", } ) - self.nexus_headers = None + self.nexus_headers: dict = {} @classmethod def sso(cls, app_slug, sso_token, sso_id=None): From 49b16bf7752ac8cf3b6e80e16d49f8fd0a8b7b94 Mon Sep 17 00:00:00 2001 From: Brian Berry Date: Sat, 23 Mar 2024 15:39:56 -0400 Subject: [PATCH 4/5] Nexus headers must have changed in response, this update ignores case --- pynxm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynxm.py b/pynxm.py index 7e2e760..527b9d6 100644 --- a/pynxm.py +++ b/pynxm.py @@ -104,7 +104,7 @@ def _make_request(self, operation, endpoint, payload=None, data=None, headers=No timeout=30, ) status_code = response.status_code - self.nexus_headers = {k: v for k, v in response.headers.items() if "X-" in k} + self.nexus_headers = {k: v for k, v in response.headers.items() if k.lower().startswith("x-")} if status_code not in (200, 201): if status_code == 429: raise LimitReachedError( From 14be0a73765d4bb399a215d3192127921f7e544e Mon Sep 17 00:00:00 2001 From: Brian Berry Date: Sat, 23 Mar 2024 15:41:58 -0400 Subject: [PATCH 5/5] Force all nexus_headers to be lower-case --- pynxm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynxm.py b/pynxm.py index 527b9d6..4486161 100644 --- a/pynxm.py +++ b/pynxm.py @@ -104,7 +104,7 @@ def _make_request(self, operation, endpoint, payload=None, data=None, headers=No timeout=30, ) status_code = response.status_code - self.nexus_headers = {k: v for k, v in response.headers.items() if k.lower().startswith("x-")} + self.nexus_headers = {k.lower(): v for k, v in response.headers.items() if k.lower().startswith("x-")} if status_code not in (200, 201): if status_code == 429: raise LimitReachedError(