question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when trying to use update() on endpoint

See original GitHub issue

Versions:

  • Python 3.9
  • Netbox 3.2.4
  • Pynetbox 6.6.2

My code (following almost exactly the documentation):

from pynetbox import api

nb = api(
    'https://netbox.local',
    token='******************************************'
)

test = nb.dcim.devices.update([
    {'id': 1, 'name': 'test'}
])

What I expected:

The device with id 1 should be renamed ‘test’.

What I actually get:

Traceback (most recent call last):
  File "/Users/bapth/PyCharm/test-env/nb-test.py", line 8, in <module>
    test = nb.dcim.devices.update([
  File "/Users/bapth/PyCharm/test-env/.env/lib/python3.9/site-packages/pynetbox/core/endpoint.py", line 374, in update
    req = Request(
  File "/Users/bapth/PyCharm/test-env/.env/lib/python3.9/site-packages/pynetbox/core/query.py", line 427, in patch
    return self._make_call(verb="patch", data=data)
  File "/Users/bapth/PyCharm/test-env/.env/lib/python3.9/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': ['Expected a list of items but got type "dict".']}

Comments

I get this error since I both updated Netbox and pynetbox. Since my code is using the update function it no longer works. I don’t know if this could change anything but I’m using an Apple M1 chip. I have also tried to update with a list of Record object but it does not work either:

from pynetbox import api

nb = api(
    'https://netbox.local',
    token='******************************************'
)

devices = nb.dcim.devices.all()
for d in devices:
    d.name = d.name + '-test'

test = nb.dcim.devices.update(devices)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Bapthscommented, Jun 8, 2022

I finally found where was my mistake. I did not specify the port of my netbox server when using the api object. By just replacing

nb = api(
    url='https://netbox.local',
    token='my-token'
)

with

nb = api(
    url='https://netbox.local:443',
    token='my-token'
)

it all works just fine… Sorry for the useless issue report and thank you again for your kick answer.

0reactions
Bapthscommented, Jun 8, 2022

Then it is working fine. So I assume pynetbox does not add these brackets… But now I can not to understand why it is working for you and not for me 🤔

Acutally it does add the brackets 🤔 I verified it by adding a print(data) in the query.py file

        ...
        if not url_override:
            if self.filters:
                params.update(self.filters)
            if add_params:
                params.update(add_params)
        print(data)  # Added line 
        req = getattr(self.http_session, verb)(
            url_override or self.url, headers=headers, params=params, json=data
        )

        if req.status_code in [204, 409] and verb == "post":
            raise AllocationError(req)
        ...

I do get [{'id': 1, 'name': 'test'}] in my terminal before raising the error. So I do not really understand where the issue come from 😔

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Windows Defender or Endpoint Protection client
Try to update Windows Defender again. If the issue persists, continue to the next step. Step 2: Make sure that the date and...
Read more >
Endpoints not installing updates - Sophos Community
I have about 20 endpoints that are down and can't reach the sus.sophosupd.com. I've ran a trace and it looks like it doesn't...
Read more >
Update User details endpoint returns 405, "error": "Method Not ...
I'm trying to update the detail of an existing user in the member table but when I tried to test the endpoint using...
Read more >
Troubleshoot Bitdefender Endpoint Security Tools update errors
Error -3 occurs when Bitdefender Endpoint Security cannot download updates over the internet. Possible causes. The error occurs usually when the endpoint cannot ......
Read more >
Troubleshooting failed LiveUpdate or definition update issues ...
Use this topic to troubleshoot issues with content updates or LiveUpdate failures on the Symantec agent. If the content is out of date, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found