Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django REST API Docs error #2021

Closed
bartdebruijn opened this issue Apr 10, 2018 · 17 comments
Closed

Django REST API Docs error #2021

bartdebruijn opened this issue Apr 10, 2018 · 17 comments
Labels
type: bug A confirmed report of unexpected behavior in the application

Comments

@bartdebruijn
Copy link

bartdebruijn commented 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

@jvanderaa
Copy link
Contributor

jvanderaa commented 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`

@jeremystretch
Copy link
Member

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 jeremystretch added the type: bug A confirmed report of unexpected behavior in the application label Apr 12, 2018
@bartdebruijn
Copy link
Author

bartdebruijn commented 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"}]}

@jvanderaa
Copy link
Contributor

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.

@mchrobak
Copy link

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

@frankfarmer
Copy link
Contributor

frankfarmer commented 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

@alejandrosalinas
Copy link

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

@bartdebruijn
Copy link
Author

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?

@alejandrosalinas
Copy link

@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.

@bartdebruijn
Copy link
Author

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
Copy link
Author

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

@amtypaldos
Copy link

Having the same issue, any update on this?

I am running python3.4.8 on Centos 7

@rbman5
Copy link

rbman5 commented May 31, 2018

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

@jamieimms
Copy link

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

@bartdebruijn
Copy link
Author

bartdebruijn commented 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.

@jeremystretch
Copy link
Member

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.

@jamieimms
Copy link

2.3.5 fixed this for me

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

9 participants