From dddd5fad3fad7f81098592e89fb22ef48bd83ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Knecht?= Date: Fri, 3 Nov 2023 23:09:33 +0100 Subject: [PATCH] core/endpoint: Get choices from PUT if POST missing If the API token is not allowed to POST on a particular endpoint, choices won't be returned in `.actions.POST`, but we can still get them in `.actions.PUT`. This commit falls back to getting choices from `.actions.PUT` instead of raising an exception when `.actions.POST` is missing. --- pynetbox/core/endpoint.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pynetbox/core/endpoint.py b/pynetbox/core/endpoint.py index a0369a7..bcf139c 100644 --- a/pynetbox/core/endpoint.py +++ b/pynetbox/core/endpoint.py @@ -585,9 +585,10 @@ def choices(self): token=self.api.token, http_session=self.api.http_session, ).options() - try: - post_data = req["actions"]["POST"] - except KeyError: + + actions = req.get("actions", {}) + post_data = actions.get("POST") or actions.get("PUT") + if post_data is None: raise ValueError( "Unexpected format in the OPTIONS response at {}".format(self.url) )