From a3b5d22dbe98a0a5ba971087592985ccfd9eddf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markku=20Leini=C3=B6?= Date: Sat, 2 Jan 2021 18:12:47 +0200 Subject: [PATCH] Change Record._endpoint_from_url() path parsing --- pynetbox/core/response.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pynetbox/core/response.py b/pynetbox/core/response.py index 2b4eabdd..1cc2d337 100644 --- a/pynetbox/core/response.py +++ b/pynetbox/core/response.py @@ -280,11 +280,13 @@ def list_parser(list_item): setattr(self, k, v) def _endpoint_from_url(self, url): - # Remove the base URL from the beginning - url = url[len(self.api.base_url) :] - if url.startswith("/"): - url = url[1:] - app, name = urlsplit(url).path.split("/")[:2] + url_path = urlsplit(url).path + base_url_path_parts = urlsplit(self.api.base_url).path.split("/") + if len(base_url_path_parts) > 2: + # There are some extra directories in the path, remove them from url + extra_path = "/".join(base_url_path_parts[:-1]) + url_path = url_path[len(extra_path) :] + app, name = url_path.split("/")[2:4] return getattr(pynetbox.core.app.App(self.api, app), name) def full_details(self):