Django REST API Docs error #1667

Closed
opened 2025-12-29 16:34:10 +01:00 by adam · 17 comments
Owner

Originally created by @bartdebruijn on GitHub (Apr 10, 2018).

Issue type

[ ] Feature request
[X] Bug report
[ ] Documentation

Environment

  • Python version: 3.4.5
  • Python version: 3.4.8
  • NetBox version: 2.3.2

Description

Hi All,

I've upgraded Netbox to v2.3.2 and now I get the error as listed in the screenshot whenever I try to access the API Docs section of Netbox.

netbox_error

The strange thing is that the API itself still works. I can access https://mywebserver.me/api/ but not https://mywebserver.me/api/docs/ as this gives the aforementioned error.

Restarting nginx did not resolve the issue, neither did rebooting the server. The server is running AWS Linux 2.

Anyone have any idea what's wrong?

Kind regards,

Bart

Originally created by @bartdebruijn on GitHub (Apr 10, 2018). <!-- Before opening a new issue, please search through the existing issues to see if your topic has already been addressed. Note that you may need to remove the "is:open" filter from the search bar to include closed issues. Check the appropriate type for your issue below by placing an x between the brackets. For assistance with installation issues, or for any other issues other than those listed below, please raise your topic for discussion on our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please note that issues which do not fall under any of the below categories will be closed. Due to an excessive backlog of feature requests, we are not currently accepting any proposals which extend NetBox's feature scope. Do not prepend any sort of tag to your issue's title. An administrator will review your issue and assign labels as appropriate. ---> ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [X] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) If you are submitting a bug report and have made any changes to the code base, please first validate that your bug can be recreated while running an official release. --> ### Environment * Python version: 3.4.5 * Python version: 3.4.8 * NetBox version: 2.3.2 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description Hi All, I've upgraded Netbox to v2.3.2 and now I get the error as listed in the screenshot whenever I try to access the API Docs section of Netbox. <img width="468" alt="netbox_error" src="https://user-images.githubusercontent.com/340639/38555131-55149204-3cc5-11e8-9e35-9d5053536ec5.PNG"> The strange thing is that the API itself still works. I can access https://mywebserver.me/api/ but not https://mywebserver.me/api/docs/ as this gives the aforementioned error. Restarting nginx did not resolve the issue, neither did rebooting the server. The server is running AWS Linux 2. Anyone have any idea what's wrong? Kind regards, Bart
adam added the type: bug label 2025-12-29 16:34:10 +01:00
adam closed this issue 2025-12-29 16:34:10 +01:00
Author
Owner

@jvanderaa commented on GitHub (Apr 12, 2018):

I am getting a similar error on a recent fresh install on Centos Python 3.4.8

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.```

I'm now getting this:
`maximum recursion depth exceeded while pickling an object`
@jvanderaa commented on GitHub (Apr 12, 2018): I am getting a similar error on a recent fresh install on Centos Python 3.4.8 ```Python 3.4.8 (default, Mar 23 2018, 10:04:27) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information.``` I'm now getting this: `maximum recursion depth exceeded while pickling an object`
Author
Owner

@jeremystretch commented on GitHub (Apr 12, 2018):

I can confirm this issue, but only when running in production. The docs work okay when running via the development server (./manage.py runserver). Not sure why.

@jeremystretch commented on GitHub (Apr 12, 2018): I can confirm this issue, but only when running in production. The docs work okay when running via the development server (`./manage.py runserver`). Not sure why.
Author
Owner

@bartdebruijn commented on GitHub (Apr 13, 2018):

Hi,

I can confirm that the API docs load when running via the development server, albeit it's slow to load. Firefox also complains that a website is slowing the browser down when opening the API docs.

One thing I noted though is that the page loads with all leafs/sections expanded. Is it possible to change this behavior to all collapsed? That might help ease off the load a bit.

I also get a small red section at the bottom of the page Error {...} and when I click on that I get the following data:

{"schemaValidationMessages":[{"level":"error","message":"Can't read from file https://<webserver>/api/docs/?format=openapi"}]}

@bartdebruijn commented on GitHub (Apr 13, 2018): Hi, I can confirm that the API docs load when running via the development server, albeit it's slow to load. Firefox also complains that a website is slowing the browser down when opening the API docs. One thing I noted though is that the page loads with all leafs/sections expanded. Is it possible to change this behavior to all collapsed? That might help ease off the load a bit. I also get a small red section at the bottom of the page `Error {...}` and when I click on that I get the following data: `{"schemaValidationMessages":[{"level":"error","message":"Can't read from file https://<webserver>/api/docs/?format=openapi"}]}`
Author
Owner

@jvanderaa commented on GitHub (Apr 16, 2018):

Note, I went ahead and upgraded the Python on the server I had just installed Netbox on (Centos 7) from 3.4.8 to 3.6 and now the API docs page is working. So perhaps a difference in Python3.4 and Python3.5 or Python3.6.

@jvanderaa commented on GitHub (Apr 16, 2018): Note, I went ahead and upgraded the Python on the server I had just installed Netbox on (Centos 7) from 3.4.8 to 3.6 and now the API docs page is working. So perhaps a difference in Python3.4 and Python3.5 or Python3.6.
Author
Owner

@mchrobak commented on GitHub (Apr 16, 2018):

We've also noticed that restarting the daemon multiple times will sometimes bring the API docs back, but we're experiencing the same issue.

@mchrobak commented on GitHub (Apr 16, 2018): We've also noticed that restarting the daemon multiple times will sometimes bring the API docs back, but we're experiencing the same issue.
Author
Owner

@frankfarmer commented on GitHub (Apr 16, 2018):

Here's the trace from running with DEBUG = True

Environment:


Request Method: GET
Request URL: http://my-netbox.local/api/docs/

Django Version: 1.11.12
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_tables2',
 'mptt',
 'rest_framework',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'drf_yasg')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.ExceptionHandlingMiddleware',
 'utilities.middleware.LoginRequiredMiddleware',
 'utilities.middleware.APIVersionMiddleware')



Traceback:

File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
  215.                 response = response.render()

File "/opt/netbox/venv/lib/python3.4/site-packages/django/template/response.py" in render
  109.                 newretval = post_callback(retval)

File "/opt/netbox/venv/lib/python3.4/site-packages/django/utils/decorators.py" in callback
  163.                             return middleware.process_response(request, response)

File "/opt/netbox/venv/lib/python3.4/site-packages/django/middleware/cache.py" in process_response
  102.                     lambda r: self.cache.set(cache_key, r, timeout)

File "/opt/netbox/venv/lib/python3.4/site-packages/django/template/response.py" in add_post_render_callback
  94.             callback(self)

File "/opt/netbox/venv/lib/python3.4/site-packages/django/middleware/cache.py" in <lambda>
  102.                     lambda r: self.cache.set(cache_key, r, timeout)

File "/opt/netbox/venv/lib/python3.4/site-packages/debug_toolbar/panels/cache.py" in wrapped
  33.         value = method(self, *args, **kwargs)

File "/opt/netbox/venv/lib/python3.4/site-packages/debug_toolbar/panels/cache.py" in set
  79.         return self.cache.set(*args, **kwargs)

File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/cache/backends/locmem.py" in set
  75.         pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)

Exception Type: RuntimeError at /api/docs/
Exception Value: maximum recursion depth exceeded while calling a Python object
@frankfarmer commented on GitHub (Apr 16, 2018): Here's the trace from running with `DEBUG = True` ``` Environment: Request Method: GET Request URL: http://my-netbox.local/api/docs/ Django Version: 1.11.12 Python Version: 3.4.0 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'corsheaders', 'debug_toolbar', 'django_filters', 'django_tables2', 'mptt', 'rest_framework', 'timezone_field', 'circuits', 'dcim', 'ipam', 'extras', 'secrets', 'tenancy', 'users', 'utilities', 'virtualization', 'drf_yasg') Installed Middleware: ('debug_toolbar.middleware.DebugToolbarMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'utilities.middleware.ExceptionHandlingMiddleware', 'utilities.middleware.LoginRequiredMiddleware', 'utilities.middleware.APIVersionMiddleware') Traceback: File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner 41. response = get_response(request) File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response 217. response = self.process_exception_by_middleware(e, request) File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response 215. response = response.render() File "/opt/netbox/venv/lib/python3.4/site-packages/django/template/response.py" in render 109. newretval = post_callback(retval) File "/opt/netbox/venv/lib/python3.4/site-packages/django/utils/decorators.py" in callback 163. return middleware.process_response(request, response) File "/opt/netbox/venv/lib/python3.4/site-packages/django/middleware/cache.py" in process_response 102. lambda r: self.cache.set(cache_key, r, timeout) File "/opt/netbox/venv/lib/python3.4/site-packages/django/template/response.py" in add_post_render_callback 94. callback(self) File "/opt/netbox/venv/lib/python3.4/site-packages/django/middleware/cache.py" in <lambda> 102. lambda r: self.cache.set(cache_key, r, timeout) File "/opt/netbox/venv/lib/python3.4/site-packages/debug_toolbar/panels/cache.py" in wrapped 33. value = method(self, *args, **kwargs) File "/opt/netbox/venv/lib/python3.4/site-packages/debug_toolbar/panels/cache.py" in set 79. return self.cache.set(*args, **kwargs) File "/opt/netbox/venv/lib/python3.4/site-packages/django/core/cache/backends/locmem.py" in set 75. pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL) Exception Type: RuntimeError at /api/docs/ Exception Value: maximum recursion depth exceeded while calling a Python object ```
Author
Owner

@alejandrosalinas commented on GitHub (Apr 27, 2018):

I also had this with CentOS and the python34* packages - upon upgrading python34-devel to python36-devel the problem disappeared.

@alejandrosalinas commented on GitHub (Apr 27, 2018): I also had this with CentOS and the python34* packages - upon upgrading python34-devel to python36-devel the problem disappeared.
Author
Owner

@bartdebruijn commented on GitHub (May 1, 2018):

I upgraded from Python version: 3.4.5 to Python version: 3.4.8 and the issue persists.

@alejandrosalinas I'm not to keen on upgrading the box to Python 3.6. Did you just upgrade the dev package, or all of it?

@bartdebruijn commented on GitHub (May 1, 2018): I upgraded from Python version: 3.4.5 to Python version: 3.4.8 and the issue persists. @alejandrosalinas I'm not to keen on upgrading the box to Python 3.6. Did you just upgrade the dev package, or all of it?
Author
Owner

@alejandrosalinas commented on GitHub (May 3, 2018):

@bartdebruijn the only python36 packages that I see in the upgraded host are:
python36.x86_64
python36-devel.x86_64
python36-libs.x86_64

Best
A.

@alejandrosalinas commented on GitHub (May 3, 2018): @bartdebruijn the only python36 packages that I see in the upgraded host are: python36.x86_64 python36-devel.x86_64 python36-libs.x86_64 Best A.
Author
Owner

@bartdebruijn commented on GitHub (May 7, 2018):

I can confirm that after installing:

python36.x86_64
python36-devel.x86_64
python36-libs.x86_64

The API docs is working again. It's a bit slow when opening, but at least it works again.

@bartdebruijn commented on GitHub (May 7, 2018): I can confirm that after installing: python36.x86_64 python36-devel.x86_64 python36-libs.x86_64 The API docs is working again. It's a bit slow when opening, but at least it works again.
Author
Owner

@bartdebruijn commented on GitHub (May 9, 2018):

Well, my victory was shortlived :( It's broken again :(

@bartdebruijn commented on GitHub (May 9, 2018): Well, my victory was shortlived :( It's broken again :(
Author
Owner

@amtypaldos commented on GitHub (May 30, 2018):

Having the same issue, any update on this?

I am running python3.4.8 on Centos 7

@amtypaldos commented on GitHub (May 30, 2018): Having the same issue, any update on this? I am running python3.4.8 on Centos 7
Author
Owner

@rbman5 commented on GitHub (May 31, 2018):

Having the same issue as well. Centos 7 with python 3.4.5-5

@rbman5 commented on GitHub (May 31, 2018): Having the same issue as well. Centos 7 with python 3.4.5-5
Author
Owner

@jamieimms commented on GitHub (Jun 6, 2018):

Still a problem for me - kinda has halted any integrations we wanted to do with Netbox

@jamieimms commented on GitHub (Jun 6, 2018): Still a problem for me - kinda has halted any integrations we wanted to do with Netbox
Author
Owner

@bartdebruijn commented on GitHub (Jun 6, 2018):

@jamieimms
What I do as a workaround is either use the API endpoints (e.g. https://myserver.net/api), or look at a standalone lab test server that is running a version of Python that supports the API docs.

It's not ideal, but I am not sure on how to fix it or what exactly is breaking.

@bartdebruijn commented on GitHub (Jun 6, 2018): @jamieimms What I do as a workaround is either use the API endpoints (e.g. https://myserver.net/api), or look at a standalone lab test server that is running a version of Python that supports the API docs. It's not ideal, but I am not sure on how to fix it or what exactly is breaking.
Author
Owner

@jeremystretch commented on GitHub (Jul 2, 2018):

This took some digging, but it appears to be an issue with Django's caching as wrapped by drf-yasg specifically on Python 3.4. Testing with Python 3.5 I could not reproduce the issue. I believe the root stems from passing cache_timeout=None (rather than 0) in the API URL definitions.

Pretty sure the change I'm about to push will fix it under NetBox v2.3.5, but please comment here if you still experience this issue under NetBox v2.3.5.

@jeremystretch commented on GitHub (Jul 2, 2018): This took some digging, but it appears to be an issue with Django's caching as wrapped by drf-yasg specifically on Python 3.4. Testing with Python 3.5 I could not reproduce the issue. I believe the root stems from passing `cache_timeout=None` (rather than `0`) in the API URL definitions. Pretty sure the change I'm about to push will fix it under NetBox v2.3.5, but please comment here if you still experience this issue under NetBox v2.3.5.
Author
Owner

@jamieimms commented on GitHub (Jul 12, 2018):

2.3.5 fixed this for me

@jamieimms commented on GitHub (Jul 12, 2018): 2.3.5 fixed this for me
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1667