AttributeError when referencing via API since latest update

91 views
Skip to first unread message

Steven

unread,
Jan 31, 2020, 2:15:14 PM1/31/20
to NetBox
Hi,

On previous versions of Netbox I was able to reference the API like:

I just updated Netbox to 2.7.2 and now when I try to go there I get:

 Server Error

There was a problem with your request. Please contact an administrator.


The complete exception is provided below:

<class 'AttributeError'>
'OrderedDict' object has no attribute 'register'

If further assistance is required, please post to the NetBox mailing list.


Has something changed in the new version, or is anyone else having same issue?

Brian Candler

unread,
Jan 31, 2020, 3:03:04 PM1/31/20
to NetBox
I haven't seen anyone else report that error.  Did you definitely restart the netbox service?

If so, please can you show the full backtrace (this will either be E-mailed to you, or you need to run with DEBUG = True)

Shujie Zhang

unread,
Feb 3, 2020, 12:34:15 PM2/3/20
to NetBox
Hi,

We started the supervisor service.

However after we rebooted the server, it's been working,

You can close the issue for now.

Thank you!

Steven

unread,
Feb 3, 2020, 1:10:18 PM2/3/20
to NetBox
Thanks Brian, I did indeed restart the service.  Not sure exactly what you need from this, but here's a lot of output...

AttributeError at /api/dcim/

'OrderedDict' object has no attribute 'register'
Request Method:GET
Request URL:https://netbox.**********.com/api/dcim/
Django Version:2.2.9
Exception Type:AttributeError
Exception Value:
'OrderedDict' object has no attribute 'register'
Exception Location:/home/****[USER]****/netbox_env/lib/python3.6/site-packages/rest_framework/compat.py in md_filter_add_syntax_highlight, line 213
Python Executable:/home/****[USER]****/netbox_env/bin/python36
Python Version:3.6.6
Python Path:
['/home/****[USER]****/netbox/netbox',
 '/home/****[USER]****/netbox_env/bin',
 '/home/****[USER]****/netbox_env/lib64/python36.zip',
 '/home/****[USER]****/netbox_env/lib64/python3.6',
 '/home/****[USER]****/netbox_env/lib64/python3.6/lib-dynload',
 '/usr/lib64/python3.6',
 '/usr/lib/python3.6',
 '/home/****[USER]****/netbox_env/lib/python3.6/site-packages']
Server time:Mon, 3 Feb 2020 17:47:15 +0000


Environment:

Request Method: GET
Request URL: https://netbox.************.com/api/dcim/

Django Version: 2.2.9
Python Version: 3.6.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'cacheops',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_rq',
 'django_tables2',
 'django_prometheus',
 'mptt',
 'rest_framework',
 'taggit',
 'taggit_serializer',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'drf_yasg']
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django_prometheus.middleware.PrometheusBeforeMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.ExceptionHandlingMiddleware',
 'utilities.middleware.LoginRequiredMiddleware',
 'utilities.middleware.APIVersionMiddleware',
 'extras.middleware.ObjectChangeMiddleware',
 'django_prometheus.middleware.PrometheusAfterMiddleware')



Traceback:

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  145.                 response = self.process_exception_by_middleware(e, request)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  143.                 response = response.render()

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/django/template/response.py" in render
  106.             self.content = self.rendered_content

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/response.py" in rendered_content
  70.         ret = renderer.render(self.data, accepted_media_type, context)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/renderers.py" in render
  725.         context = self.get_context(data, accepted_media_type, renderer_context)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/renderers.py" in get_context
  687.             'description': self.get_description(view, response.status_code),

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/renderers.py" in get_description
  602.         return view.get_view_description(html=True)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/views.py" in get_view_description
  245.         return func(self, html)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/views.py" in get_view_description
  61.         return formatting.markup_description(description)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/utils/formatting.py" in markup_description
  63.         description = apply_markdown(description)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/compat.py" in apply_markdown
  156.         md_filter_add_syntax_highlight(md)

File "/home/****[USER]****/nb_env/lib/python3.6/site-packages/rest_framework/compat.py" in md_filter_add_syntax_highlight
  213.         md.preprocessors.register(CodeBlockPreprocessor(), 'highlight', 40)

Exception Type: AttributeError at /api/dcim/
Exception Value: 'OrderedDict' object has no attribute 'register'

Steven

unread,
Feb 4, 2020, 9:47:26 AM2/4/20
to NetBox
Hi Shujie Zhang,

I believe you posted in the wrong thread lol.  My issue is very much still ongoing ;) 

Brian Candler

unread,
Feb 4, 2020, 1:34:29 PM2/4/20
to NetBox
That's weird - there's nothing from netbox itself in that backtrace.  (Why on earth syntax highlighters are being registered for an API endpoint, I have no idea)

You didn't get another other part to the backtrace, such as "During handling of this exception another error occurred...", did you?

You do have the exact same versions of all packages as listed in requirements.txt?

Steven

unread,
Feb 4, 2020, 2:34:19 PM2/4/20
to NetBox
Hi Brian, 
Nope, didn't get another part of the backtrace saying anything else. Let me double-check about the versions for requirements.txt and get back to you, thank you for your suggestions.


Brian Candler

unread,
Feb 4, 2020, 3:47:59 PM2/4/20
to NetBox
Out of interest, are you hitting that endpoint with curl or a browser?

I get JSON back form /api/dcim/ with curl - the browser gives pretty rendering.  But both are working for me.  (netbox 2.7.4, Ubuntu 16.04, python 3.5.2)

Steven

unread,
Feb 5, 2020, 2:16:37 PM2/5/20
to NetBox
Hi Brian.,

I was hitting that endpoint in the browser.  Instead of the pretty JSON rendering we get this attribute error.  My colleague just opened an issue about this here> https://github.com/netbox-community/netbox/issues/4097

Brian Candler

unread,
Feb 5, 2020, 2:29:03 PM2/5/20
to NetBox
And what about curl?  I'm just wondering about any ways to narrow this down (e.g. whether it's affected by request headers) since I don't see the problem here.

Steven

unread,
Feb 5, 2020, 2:32:04 PM2/5/20
to NetBox
Curl seems to be working fine for us

Brian Candler

unread,
Feb 6, 2020, 3:29:10 AM2/6/20
to NetBox
Good.  So I suggest the next step is: check what headers your browser is sending with the request (use your browser's debug console - or just use tcpdump on the netbox port).  Add these headers to the curl request (using -H "Header: value") until you can replicate the problem with curl.

When you've done that, post here the curl command which replicates the problem for you - and we can try to see if it replicates for us too.

Jeremy Stretch

unread,
Feb 6, 2020, 9:22:14 AM2/6/20
to Brian Candler, NetBox
> Why on earth syntax highlighters are being registered for an API endpoint, I have no idea

Django REST Framework is clever enough to toggle the type of data it returns based on the user-agent header. If the request looks like it's coming from a human, it returns a nice HTML page with syntax highlighting and all that good stuff. Otherwise, such as when using curl with default headers, it returns raw JSON. You can force one or the other by appending ?format=api or ?format=json to the request.

From the stack trace, it looks like DRF is having an issue with Markdown. Per requirements.txt, NetBox requires Markdown v2.6.11. What version do you have installed?

Someone opened a related bug yesterday, which was apparently resolved by rebuilding his virtual environment.


On Thu, Feb 6, 2020 at 3:29 AM Brian Candler <b.ca...@pobox.com> wrote:
Good.  So I suggest the next step is: check what headers your browser is sending with the request (use your browser's debug console - or just use tcpdump on the netbox port).  Add these headers to the curl request (using -H "Header: value") until you can replicate the problem with curl.

When you've done that, post here the curl command which replicates the problem for you - and we can try to see if it replicates for us too.

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/4a1c870b-2bf0-4b4c-8192-b71a3e801644%40googlegroups.com.


--
Jeremy Stretch
Sr. Network Automation Engineer
Network to Code, LLC

Steven

unread,
Feb 6, 2020, 10:40:54 AM2/6/20
to NetBox
Hi Jeremy and Brian,

Yes that was one of our team members.  We ended up finding the culprit.  We rolled back to Netbox 2.6.12, tested and it worked, then when we stepped up to 7.0 it broke.  The update was using "djangorestframework==3.10.3" which is what broke it for us.  We downgraded that to 3.9.4 and it worked.

Then we created a new virtual env and started from scratch and it is working, so it was an issue between newest djangorestframework version and our virtual environment for some reason.

Thank you very much for your time and efforts guys.

Brian Candler

unread,
Feb 6, 2020, 10:59:28 AM2/6/20
to NetBox
I don't understand.  requirements.txt says

djangorestframework==3.10.3

so you had the correct version installed, and there should be no need to change to 3.9.4.

There may be a bug in some transitive dependency; transitive dependencies in pip3 are totally broken.  You'd have to do a full "pip3 list" on a broken installation and we compare it to one of ours to see what's different.

I have been bitten by different variations of this over time.  Personally I think netbox's requirements.txt should nail versions of all its dependencies - including indirect dependencies - but this was rejected.
Reply all
Reply to author
Forward
0 new messages