Closed 1NoOne1 closed 6 years ago
Hi, sorry, didn't see this come through. PATCH support is coming, probably via an .update()
method, but PUT should work. Have a look at the response docs for how to manipulate an object. Basically, you'll want to .get()
change the attributes via assignment (e.g. device.name = 'test'
) then call .save()
to send the PUT.
@zachmoody Something like this?
>>> test3 = nb.virtualization.virtual_machines.get(201)
>>> test3.name = "newname"
>>> test3.save()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/konaya/.local/lib/python3.6/site-packages/pynetbox/lib/response.py", line 233, in save
if req.put(self.serialize()):
File "/home/konaya/.local/lib/python3.6/site-packages/pynetbox/lib/query.py", line 242, in put
raise RequestError(req)
pynetbox.lib.query.RequestError: The request failed with code 500 Internal Server Error
>>>
Yeah, that should work. I don't have an easy way of seeing what that endpoint expects at the moment, but you can catch the RequestError
with something like:
from pynetbox import RequestError
try:
test3.save()
except RequestError as err:
raise Exception(err.error)
to get the response from NetBox.
Huh.
<pre><strong><class 'TypeError'></strong><br />
int() argument must be a string, a bytes-like object or a number, not 'dict'</pre>
The original request object is also returned in the exception as the .req
attribute. I'd have to go digging around in the requests
docs to find it, but you should be able to see the body of the request and maybe pick out where the errant dict is from that.
It looks like using HTTL requestes, we can do PUT as well as POST on an object (looking at the swagger api docs). However, I am trying to do the following:
I am using the netbox version
2.2.8
and pynetbox3.0.1
Any help is appreciated. Any way that would work other than this is also good.
the first and seconds steps, I got through somehow. [The documentation is pretty sparse and I don't know how to use or modify]. I am trying to use the PUT for the third step...but it is failing.
I have My code like the below.