Code Monkey home page Code Monkey logo

Comments (7)

SA0TAY avatar SA0TAY commented on May 28, 2024

I can confirm this.

Jun 25 09:54:51 dcim gunicorn[13044]: b'' - - [25/Jun/2018:07:54:51 +0000] "GET //api/dcim/devices/125/ HTTP/1.0" 404 13580 "-" "python-requests/2.10.0"

Removing the extra slash (it's a forward slash, by the way – a backslash is a "\") made it work as predicted:

Jun 25 09:55:58 dcim gunicorn[13044]: b'' - - [25/Jun/2018:07:55:58 +0000] "GET /api/dcim/devices/125/ HTTP/1.0" 200 1986 "-" "python-requests/2.10.0"

from pynetbox.

SA0TAY avatar SA0TAY commented on May 28, 2024

I'm not sure if I'd call it a bug, though. The example in README.md of pynetbox clearly shows that an ending slash shouldn't be included in the URL. Sure, it happened to work with multiple slashes in succession before, but that is by no means a defined behaviour.

Either make the documentation more explicit in this regard, make pynetbox autodetect and discard any extraneous slashes, or convince the Netbox project to update their API spec to allow for extra slashes. The former alternatives being the better ones, IMHO.

from pynetbox.

zachmoody avatar zachmoody commented on May 28, 2024

I think pynetbox has always raised a RequestError when passed a trailing slash. I've thought about sanitizing the url, but haven't gotten around to it. I tested it on 2.3.3 and 2.3.4 and got it to raise and exception on each, but I also couldn't reproduce the issue. 🤷‍♂️

from pynetbox.

bdlamprecht avatar bdlamprecht commented on May 28, 2024

So I'm not sure what I'm doing wrong and how @konaya was able to

Remove the extra slash

and not encounter the error with v2.3.4.

I'm not manually add a / anywhere, the / gets added automatically by pynetbox when I do a nb.dcim.sites.get(slug='0am')

from pynetbox.

zachmoody avatar zachmoody commented on May 28, 2024

I'm not sure that pynetbox is adding it. I've tested with the docker image on docker-hub and couldn't reproduce the behavior.

from pynetbox.

bdlamprecht avatar bdlamprecht commented on May 28, 2024

Ah, I think I found what I was doing incorrectly.
For my original example for this issue, I was using the following code:

import pynetbox

token     = '0123456789abcdef0123456789abcdef01234567'
test_url  = 'http://node2.internal:10123/'
node_url  = 'http://node3.internal:10123/'

nb_url    = test_url
nb        = pynetbox.api(nb_url,token)

This worked fine for all versions of NetBox through v2.3.3, however, in v2.3.4, I had to remove the trailing forward slash (/) from the end of the url:

import pynetbox

token     = '0123456789abcdef0123456789abcdef01234567'
test_url  = 'http://node2.internal:10123'
node_url  = 'http://node3.internal:10123'

nb_url    = test_url
nb        = pynetbox.api(nb_url,token)

After I made that change, everything started to work fine once again.

Like @konaya said, the README.md of pynetbox does show the url without the trailing slash, however I don't know that I would call it clearly :)

@zachmoody I think it would be a good idea to either, (1) sanitize it like you mentioned wanting to or (2) updating the documentation to make it clear that including the trailing / might cause problems.

from pynetbox.

zachmoody avatar zachmoody commented on May 28, 2024

Yeah, I'd like to sanitize the input. I'll leave this issue open to track that.

from pynetbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.