pynetbox
pynetbox copied to clipboard
Getting a weird error message when trying to create device type
When trying to execute the following code: model = 'DCS-7280SR-48C6' nb.dcim.device_types.create([{ "model": model, "manufacturer": 3, "slug": model.lower() }])
I get the following error: The request failed with code 400 Bad Request: [{'non_field_errors': ['The fields manufacturer, model must make a unique set.', 'The fields manufacturer, slug must make a unique set.']}]
But the object gets created in netbox, so what does the error mean? The plan is to create device types on in a for loop, this is just an example which throws the same error. Running pynetbox version 6.6.2 and Netbox version 3.2.3
It sounds like the request is being sent to NetBox twice, but I'm not sure why that would happen.
Works for me (lines split for readability):
>>> pynetbox.__version__
'6.6.2'
>>> nb.status()["netbox-version"]
'3.2.4'
>>> list(nb.dcim.device_types.filter())
[Generic]
>>> nb.dcim.device_types.create([{"model": "Model1", "manufacturer": 1, "slug": "model1"}])
[Model1]
>>> list(nb.dcim.device_types.filter())
[Generic, Model1]
>>> nb.dcim.device_types.create([{"model": "Model2", "manufacturer": 1, "slug": "model2"}])
[Model2]
>>> list(nb.dcim.device_types.filter())
[Generic, Model1, Model2]
>>> nb.dcim.device_types.create([{"model": "Model2", "manufacturer": 1, "slug": "model2"}])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/markku/devel/pynetbox/venv/lib/python3.7/site-packages/pynetbox/core/endpoint.py", line 318, in create
).post(args[0] if args else kwargs)
File "/home/markku/devel/pynetbox/venv/lib/python3.7/site-packages/pynetbox/core/query.py", line 399, in post
return self._make_call(verb="post", data=data)
File "/home/markku/devel/pynetbox/venv/lib/python3.7/site-packages/pynetbox/core/query.py", line 287, in _make_call
raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request:
[{'non_field_errors':
['The fields manufacturer, model must make a unique set.', 'The fields manufacturer, slug must make a unique set.']
}]
>>> list(nb.dcim.device_types.filter())
[Generic, Model1, Model2]
>>>
Used requests for that one part of my script since i have no idea why that error appears, if i just run: model = 'DCS-7280SR-48C6' nb.dcim.device_types.create([{ "model": model, "manufacturer": 3, "slug": model.lower() }]) I get the error, and if i run it in a loop i get it as well (Ran it in the python IDE, since i suspected the loop was the thing causing the issue), so i will use requests for now, until I have the time to look into what is actually going on, because creating devices, sites, etc. is no problem it is only with that specific object i have the issue.
@mickmortensen Is this still an issue?