Unable to add secrets in netbox through the API using a python script (using netbox secrets plugin) #8490

Closed
opened 2025-12-29 20:37:22 +01:00 by adam · 5 comments
Owner

Originally created by @pmarchal25 on GitHub (Aug 21, 2023).

NetBox version

v3.5.7 with netbox_secrets_plugin v1.8.5

Python version

3.8

Steps to Reproduce

  1. Create a python sript as the following:

### secret_key=fichero.read()
nb = pynetbox.api(url=url, token=token)
#where url is the IP address of your netbox installation, token is the token associated to your user netbox to access to the >#API, and secret_key is your private_key with you can decrypt or add new secrets to netbox
session_key = nb.plugins.secrets.session_keys.create(preserve_key=True, private_key=secret_key)
session = requests.Session()
session.headers = {'X-Session-Key': session_key.session_key}
nb.http_session = session
nb.plugins.secrets.secrets.create(
assigned_object_type='dcim.device',
assigned_object_id=426,
name="test",
plaintext="1234",
role=1
)

  1. Run the script to try to add the secret.
  2. Check that the update has been done correctly.

Expected Behavior

The secret has been added correctly

Observed Behavior

I think that the problem maybe is a bug in the plugin but i am not sure.
The logs show:
_Traceback (most recent call last):
File "prueba4.py", line 49, in
session_key = nb.plugins.secrets.session_keys.create(preserve_key=True, private_key=secret_key)
File "/home/ubuntu/.local/lib/python3.6/site-packages/pynetbox/core/endpoint.py", line 415, in create
).post(args[0] if args else kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/pynetbox/core/query.py", line 357, in post
return self._make_call(verb="post", data=data)
File "/home/ubuntu/.local/lib/python3.6/site-packages/pynetbox/core/query.py", line 247, in make_call
raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request but more specific details were not returned in json. Check the NetBox Logs or investigate this exception's error attribute.

Originally created by @pmarchal25 on GitHub (Aug 21, 2023). ### NetBox version v3.5.7 with netbox_secrets_plugin v1.8.5 ### Python version 3.8 ### Steps to Reproduce 1. Create a python sript as the following: > **### _secret_key=fichero.read() > nb = pynetbox.api(url=url, token=token) > #where url is the IP address of your netbox installation, token is the token associated to your user netbox to access to the >#API, and secret_key is your private_key with you can decrypt or add new secrets to netbox > session_key = nb.plugins.secrets.session_keys.create(preserve_key=True, private_key=secret_key) > session = requests.Session() > session.headers = {'X-Session-Key': session_key.session_key} > nb.http_session = session > nb.plugins.secrets.secrets.create( > assigned_object_type='dcim.device', > assigned_object_id=426, > name="test", > plaintext="1234", > role=1 > )_** 2. Run the script to try to add the secret. 3. Check that the update has been done correctly. ### Expected Behavior The secret has been added correctly ### Observed Behavior I think that the problem maybe is a bug in the plugin but i am not sure. The logs show: **_Traceback (most recent call last): File "prueba4.py", line 49, in <module> session_key = nb.plugins.secrets.session_keys.create(preserve_key=True, private_key=secret_key) File "/home/ubuntu/.local/lib/python3.6/site-packages/pynetbox/core/endpoint.py", line 415, in create ).post(args[0] if args else kwargs) File "/home/ubuntu/.local/lib/python3.6/site-packages/pynetbox/core/query.py", line 357, in post return self._make_call(verb="post", data=data) File "/home/ubuntu/.local/lib/python3.6/site-packages/pynetbox/core/query.py", line 247, in _make_call raise RequestError(req) pynetbox.core.query.RequestError: The request failed with code 400 Bad Request but more specific details were not returned in json. Check the NetBox Logs or investigate this exception's error attribute._**
adam added the type: bug label 2025-12-29 20:37:22 +01:00
adam closed this issue 2025-12-29 20:37:22 +01:00
Author
Owner

@abhi1693 commented on GitHub (Aug 21, 2023):

Please show us the logs from netbox as well

@abhi1693 commented on GitHub (Aug 21, 2023): Please show us the logs from netbox as well
Author
Owner

@pmarchal25 commented on GitHub (Aug 21, 2023):

where can i find them?

@pmarchal25 commented on GitHub (Aug 21, 2023): where can i find them?
Author
Owner

@abhi1693 commented on GitHub (Aug 21, 2023):

You should see it on your netbox logging system.

@abhi1693 commented on GitHub (Aug 21, 2023): You should see it on your netbox logging system.
Author
Owner

@pmarchal25 commented on GitHub (Aug 21, 2023):

In the server web or in the Virtual machine where i have installed netbox?

@pmarchal25 commented on GitHub (Aug 21, 2023): In the server web or in the Virtual machine where i have installed netbox?
Author
Owner

@abhi1693 commented on GitHub (Aug 21, 2023):

I did not realize this but this should be opened in https://github.com/Onemind-Services-LLC/netbox-secrets

@abhi1693 commented on GitHub (Aug 21, 2023): I did not realize this but this should be opened in https://github.com/Onemind-Services-LLC/netbox-secrets
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8490