Request
pynetbox.core.query.RequestError (Exception)
Basic Request Exception.
More detailed exception that returns the original requests object for inspection. Along with some attributes with specific details from the requests object. If return is json we decode and add it to the message.
Examples
try:
nb.dcim.devices.create(name="destined-for-failure")
except pynetbox.RequestError as e:
print(e.error)
Source code in pynetbox/core/query.py
class RequestError(Exception):
"""Basic Request Exception.
More detailed exception that returns the original requests object
for inspection. Along with some attributes with specific details
from the requests object. If return is json we decode and add it
to the message.
## Examples
```python
try:
nb.dcim.devices.create(name="destined-for-failure")
except pynetbox.RequestError as e:
print(e.error)
```
"""
def __init__(self, req):
if req.status_code == 404:
self.message = "The requested url: {} could not be found.".format(req.url)
else:
try:
self.message = "The request failed with code {} {}: {}".format(
req.status_code, req.reason, req.json()
)
except ValueError:
self.message = (
"The request failed with code {} {} but more specific "
"details were not returned in json. Check the NetBox Logs "
"or investigate this exception's error attribute.".format(
req.status_code, req.reason
)
)
super().__init__(self.message)
self.req = req
self.request_body = req.request.body
self.base = req.url
self.error = req.text
def __str__(self):
return self.message
pynetbox.core.query.ContentError (Exception)
Content Exception.
If the API URL does not point to a valid NetBox API, the server may return a valid response code, but the content is not json. This exception is raised in those cases.
Source code in pynetbox/core/query.py
class ContentError(Exception):
"""Content Exception.
If the API URL does not point to a valid NetBox API, the server may
return a valid response code, but the content is not json. This
exception is raised in those cases.
"""
def __init__(self, req):
super().__init__(req)
self.req = req
self.request_body = req.request.body
self.base = req.url
self.error = (
"The server returned invalid (non-json) data. Maybe not a NetBox server?"
)
def __str__(self):
return self.error
pynetbox.core.query.AllocationError (Exception)
Allocation Exception.
Used with available-ips/available-prefixes when there is no room for allocation and NetBox returns 409 Conflict.
Source code in pynetbox/core/query.py
class AllocationError(Exception):
"""Allocation Exception.
Used with available-ips/available-prefixes when there is no
room for allocation and NetBox returns 409 Conflict.
"""
def __init__(self, req):
super().__init__(req)
self.req = req
self.request_body = req.request.body
self.base = req.url
self.error = "The requested allocation could not be fulfilled."
def __str__(self):
return self.error