POST to available-ips API call sometimes returns a body for an exhausted prefix #5504

Closed
opened 2025-12-29 19:28:46 +01:00 by adam · 5 comments
Owner

Originally created by @ston1th on GitHub (Oct 10, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.0.7

Python version

3.9

Steps to Reproduce

Create a new IPAM prefix which is already full like this: 192.168.101.0/32

Then note down the ID of the created prefix. It can be found in the URL bar of the browser.

  • For example: https://demo.netbox.dev/ipam/prefixes/78/ - 78 is the ID.

Next create an API token for your user.

Now call the available-ips API and insert the prefix ID and token values:

token="<token>"
id="<id>"
for i in {0..10}; do
  curl -v -XPOST -H "Content-Type: application/json" \
    -H "Authorization: Token $token" \
    "https://demo.netbox.dev/api/ipam/prefixes/$id/available-ips/" 2>&1 \
    | grep -q "Excess found:" && echo "found" || echo "not found"
done

Output:

found
not found
found
found
found
not found
not found
found
not found
found
not found

Explanation:

The above curl command calls the same API 10 times.

When curl notices a resoponse body for a HTTP status code which does normally not include a response body (like status code 204) it reports this via Excess found:.

Now normally there shouldn't be an Excess found: and thus the output should show not found 10 times.

For every found in the output the netbox API returned a response body containing this:

{"detail":"An insufficient number of IP addresses are available within 192.168.101.0/32 (1 requested, 0 available)"}

Now I don't know why this only happens sometimes (maybe this has somthing to do with how the request is built in django) but in any case there should be no response body at all for HTTP 204.

Expected Behavior

More information on the HTTP status code 204:

The code causing this:
e05fa5c302/netbox/ipam/api/mixins.py (L127-L134)

A fix would be rather simple:

  • Return an empty response and HTTP_204_NO_CONTENT
  • or return a response, but change the status to somthing else that fits the case.

Observed Behavior

I think most HTTP clients expect no response body when presented with a HTTP 204 No Content.

The funny thing is sometimes there is no body returned and sometimes there is.

So for example to golang http client logs these violations to the console:

2021/10/10 13:13:42 Unsolicited response received on idle HTTP channel starting with "{\"detail\":\"An insufficient number of IP addresses are available within 192.168.101.0/32 (1 requested, 0 available)\"}"; err=<nil>
Originally created by @ston1th on GitHub (Oct 10, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.0.7 ### Python version 3.9 ### Steps to Reproduce Create a new IPAM prefix which is already full like this: `192.168.101.0/32` Then note down the ID of the created prefix. It can be found in the URL bar of the browser. * For example: `https://demo.netbox.dev/ipam/prefixes/78/` - `78` is the ID. Next create an API token for your user. Now call the `available-ips` API and insert the prefix ID and token values: ``` token="<token>" id="<id>" for i in {0..10}; do curl -v -XPOST -H "Content-Type: application/json" \ -H "Authorization: Token $token" \ "https://demo.netbox.dev/api/ipam/prefixes/$id/available-ips/" 2>&1 \ | grep -q "Excess found:" && echo "found" || echo "not found" done ``` Output: ``` found not found found found found not found not found found not found found not found ``` Explanation: The above curl command calls the same API 10 times. When curl notices a resoponse body for a HTTP status code which does normally not include a response body (like status code 204) it reports this via `Excess found:`. Now normally there shouldn't be an `Excess found:` and thus the output should show `not found` 10 times. For every `found` in the output the netbox API returned a response body containing this: ``` {"detail":"An insufficient number of IP addresses are available within 192.168.101.0/32 (1 requested, 0 available)"} ``` Now I don't know why this only happens sometimes (maybe this has somthing to do with how the request is built in django) but in any case there should be no response body at all for `HTTP 204`. ### Expected Behavior More information on the HTTP status code 204: * https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204 The code causing this: https://github.com/netbox-community/netbox/blob/e05fa5c30285a7db9c7b80f52c883523401ef01c/netbox/ipam/api/mixins.py#L127-L134 A fix would be rather simple: * Return an empty response and `HTTP_204_NO_CONTENT` * or return a response, but change the status to somthing else that fits the case. ### Observed Behavior I think most HTTP clients expect no response body when presented with a `HTTP 204 No Content`. The funny thing is sometimes there is no body returned and sometimes there is. So for example to golang http client logs these violations to the console: ``` 2021/10/10 13:13:42 Unsolicited response received on idle HTTP channel starting with "{\"detail\":\"An insufficient number of IP addresses are available within 192.168.101.0/32 (1 requested, 0 available)\"}"; err=<nil> ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:28:46 +01:00
adam closed this issue 2025-12-29 19:28:46 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 11, 2021):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (Oct 11, 2021): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also **be sure that your report does not reference data on the public NetBox demo**, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@ston1th commented on GitHub (Oct 11, 2021):

@jeremystretch I updated the issue description with more (hopefully enough) information.

@ston1th commented on GitHub (Oct 11, 2021): @jeremystretch I updated the issue description with more (hopefully enough) information.
Author
Owner

@markkuleinio commented on GitHub (Dec 11, 2021):

The fix (change return code from 204 to 409) will require change in pynetbox as well, I'll look into it.

@markkuleinio commented on GitHub (Dec 11, 2021): The fix (change return code from 204 to 409) will require change in `pynetbox` as well, I'll look into it.
Author
Owner

@jeremystretch commented on GitHub (Dec 11, 2021):

Thanks @markkuleinio, let me know if I can be of any help.

@jeremystretch commented on GitHub (Dec 11, 2021): Thanks @markkuleinio, let me know if I can be of any help.
Author
Owner

@markkuleinio commented on GitHub (Dec 11, 2021):

PR submitted for pynetbox: https://github.com/netbox-community/pynetbox/pull/423

@markkuleinio commented on GitHub (Dec 11, 2021): PR submitted for `pynetbox`: https://github.com/netbox-community/pynetbox/pull/423
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5504