pynetbox icon indicating copy to clipboard operation
pynetbox copied to clipboard

render_config tries wrong url when Netbox is behind reverse proxy

Open dsecik opened this issue 2 years ago • 1 comments

pynetbox version

v7.1.0

NetBox version

v3.6.3

Python version

3.9

Steps to Reproduce

#!/usr/bin/python3

import pynetbox

def main():
  nb = pynetbox.api(url="netbox_url", token="my_netbox_token")
  device = nb.dcim.devices.get(680)
  print(device.render_config.create()["content"])

if __name__ == "__main__":
    main()

Expected Behavior

It should return rendered context for device id 680.

Observed Behavior

Works fine when pointed directly to the netbox URL. How ever when used with nginx reverse proxy it fails with:

Traceback (most recent call last):
  File "/home/daniel.secik/./test2.py", line 11, in <module>
    main()
  File "/home/daniel.secik/./test2.py", line 8, in main
    print(device.render_config.create()["content"])
  File "/usr/lib/python3.9/site-packages/pynetbox/core/endpoint.py", line 706, in create
    req = Request(**self.request_kwargs).post(data)
  File "/usr/lib/python3.9/site-packages/pynetbox/core/query.py", line 368, in post
    return self._make_call(verb="post", data=data)
  File "/usr/lib/python3.9/site-packages/pynetbox/core/query.py", line 258, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The requested url: <proxy_url>:8080/netbox/api/680//680/render-config/ could not be found.

We only saw this with render_config, other api calls work fine with proxy.

Proxy config:
    location ~ "^/netbox/api/" {
        limit_except GET POST {
            deny all;
        }

        rewrite netbox/(.*)$ /$1 break;
        proxy_set_header Accept "application/json";
        proxy_set_header Content-Type "application/json";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass <netbox_url>;
    }

dsecik avatar Oct 24 '23 04:10 dsecik