Trying to add a new secret to a device from a python script that interacts with the api #91
Closed
pmarchal25
started this conversation in
General
Replies: 1 comment 1 reply
-
I think the URL for the API should be: http://192.168.27.203:8000/api/plugins/secrets/get-session-key |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone, I want to know how to add a secret to a device with a python script. When i had netbox version 2.8.6 i could do it interacting by the API. The problem is that in the new version (3.5.7) it's not working. The script test is something like that:
url = "http://192.168.27.203:8000"
token = "375ba268ee405dc41bf740610b6627bfa5f42e5d"
fichero=open("/home/ubuntu/python/VS/pedrojmNetbox3Key.txt","r")
secret_key=fichero.read()
nb = pynetbox.api(url=url, token=token, private_key=secret_key)
user="test"
key="test"
nb.plugins.secrets.secrets.create(
display = user,
role=1,
assigned_object_id = 426,
plaintext = "test",
)
being secret_key the secret session key with which i can add new secrets.
The problem is that when i try to run the script this error appear:
Traceback (most recent call last):
File "prueba.py", line 22, in
nb.plugins.secrets.secrets.create(
File "/usr/local/lib/python3.6/dist-packages/pynetbox/core/app.py", line 67, in getattr
self._set_session_key()
File "/usr/local/lib/python3.6/dist-packages/pynetbox/core/app.py", line 78, in _set_session_key
http_session=self.api.http_session,
File "/usr/local/lib/python3.6/dist-packages/pynetbox/core/query.py", line 225, in get_session_key
raise RequestError(req)
pynetbox.core.query.RequestError: The requested url: http://192.168.27.203:8000/api/secrets/get-session-key/?preserve_key=True could not be found.
and i think that maybe in this new version they way to use the session key is different than in the older version, but i don't know how to use.
Thank you so much for your time.
Best Regards.
Pedro
Beta Was this translation helpful? Give feedback.
All reactions