Skip to content

Commit e91d12f

Browse files
author
Zach Moody
authored
Merge pull request #323 from markkuleinio/change-path-parsing
Change Record._endpoint_from_url() path parsing to ignore host:port
2 parents 243208b + a3b5d22 commit e91d12f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pynetbox/core/response.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ def list_parser(list_item):
280280
setattr(self, k, v)
281281

282282
def _endpoint_from_url(self, url):
283-
# Remove the base URL from the beginning
284-
url = url[len(self.api.base_url) :]
285-
if url.startswith("/"):
286-
url = url[1:]
287-
app, name = urlsplit(url).path.split("/")[:2]
283+
url_path = urlsplit(url).path
284+
base_url_path_parts = urlsplit(self.api.base_url).path.split("/")
285+
if len(base_url_path_parts) > 2:
286+
# There are some extra directories in the path, remove them from url
287+
extra_path = "/".join(base_url_path_parts[:-1])
288+
url_path = url_path[len(extra_path) :]
289+
app, name = url_path.split("/")[2:4]
288290
return getattr(pynetbox.core.app.App(self.api, app), name)
289291

290292
def full_details(self):

0 commit comments

Comments
 (0)