nautobot / pynautobot

Nautobot Python SDK
https://pynautobot.readthedocs.io/en/latest/index.html
Apache License 2.0
36 stars 32 forks source link

API URL Endpoint doesn't handle "/" #83

Closed mattmiller87 closed 1 year ago

mattmiller87 commented 1 year ago

Re-producable using:

Local Environment

Nautobot Environment

Example

In Nautobot, Create a Regex Rule:

In Pynautobot, update the regex rule to Enabled: True

import os
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
import pynautobot
import requests
url = "http://localhost:8080"
token = "ba21aea2b4f83376c3cfc8b9237660e72040dd83"
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
nautobot = pynautobot.api(url=url, token=token)
endpoint = getattr(nautobot.plugins, "data-validation-engine")
endpoint = getattr(endpoint, "rules/regex")
nautobot.http_session.verify = False
endpoint.url

at this point we see endpoint.url = 'http://localhost:8080/api/plugins/data-validation-engine/rules/regex'

rgs = endpoint.all()
rgs[0].endpoint.url

at this point we see rgs[0].endpoint.url = 'http://localhost:8080/api/plugins/data-validation-engine/rules'

rgs[0].serialize()
rgs[0].enabled = True
rgs[0].save()

error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mattmiller/Documents/playground/env/lib/python3.10/site-packages/pynautobot/core/endpoint.py", line 109, in all
    return response_loader(req.get(), self.return_obj, self)
  File "/Users/mattmiller/Documents/playground/env/lib/python3.10/site-packages/pynautobot/core/query.py", line 326, in get
    return req_all()
  File "/Users/mattmiller/Documents/playground/env/lib/python3.10/site-packages/pynautobot/core/query.py", line 284, in req_all
    req = self._make_call(add_params=add_params)
  File "/Users/mattmiller/Documents/playground/env/lib/python3.10/site-packages/pynautobot/core/query.py", line 257, in _make_call
    raise RequestError(req)
pynautobot.core.query.RequestError: The requested url: http://localhost:8080/api/plugins/data-validation-engine/rules/ could not be found.

Links to code

"rules/regex"