binascii.Error incorrect padding #4306

Closed
opened 2025-12-29 18:34:33 +01:00 by adam · 8 comments
Owner

Originally created by @nniehoff on GitHub (Nov 25, 2020).

Environment

  • Python version: 3.7.9
  • NetBox version: 2.9.8

Occasionaly a user connects to NetBox with a web browser, typically Chrome, and is presented with a binascii.Error Incorrect padding error, see attached screenshot.
image (1)

Looking I the logs I see the following stack trace:

binascii:Error: Incorrect padding
Traceback(most recent call last):
File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "./utilities/middleware.py", line 77, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "./utilities/middleware.py", line 32, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "./utilities/middleware.py", line 62, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "./extras/middleware.py", line 30, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 179, in _get_response
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 554, in wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 73, in view
File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 944, in wrapper
File "/var/app/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 101, in dispatch
File "./netbox/views.py", line 193, in get
File "/var/app/venv/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
File "./utilities/querysets.py", line 22, in restrict
File "/var/app/venv/lib/python3.7/site-packages/django/utils/functional.py", line 240, in inner
File "/var/app/venv/lib/python3.7/site-packages/django/utils/functional.py", line 376, in _setup
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 23, in <lambda>
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 11, in get_user
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 174, in get_user
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 58, in _get_user_session_key
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 65, in __getitem__
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 220, in _get_session
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 44, in load
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 122, in decode
File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 126, in _legacy_decode
File "/usr/lib64/python3.7/base64.py", line 87, in b64decode

We use New Relic for APM monitoring so ignore the intermixed newrelic packages, this issue happens without new relic as well.

This seems to be user and browser specific. It doesn't always happen, it doesn't happen to the same users, and usually, if the user switches web browsers they are able to connect to NetBox.

I have been able to reproduce this issue occasionally by upgrading minor versions of NetBox (i.e. 2.9.7 -> 2.9.8) a quick fix although a big hammer fix is to truncate the django_session table, but this seems drastic. This happens often enough I feel it is worth reporting.

Steps to Reproduce

  1. Launch a web browser and connect to NetBox, this only happens occasionally

Expected Behavior

The NetBox UI is displayed

Observed Behavior

The user is presented with the error captured above

Originally created by @nniehoff on GitHub (Nov 25, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/g/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.7.9 * NetBox version: 2.9.8 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> Occasionaly a user connects to NetBox with a web browser, typically Chrome, and is presented with a binascii.Error Incorrect padding error, see attached screenshot. ![image (1)](https://user-images.githubusercontent.com/14947575/100237803-a6c4b180-2eec-11eb-9590-3ff82e6109a3.png) Looking I the logs I see the following stack trace: ``` binascii:Error: Incorrect padding Traceback(most recent call last): File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "./utilities/middleware.py", line 77, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "./utilities/middleware.py", line 32, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "./utilities/middleware.py", line 62, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "./extras/middleware.py", line 30, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "/var/app/venv/lib/python3.7/site-packages/django/utils/deprecation.py", line 114, in __call__ File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 1197, in _wrapper File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner File "/var/app/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 179, in _get_response File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 554, in wrapper File "/var/app/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 73, in view File "/var/app/venv/lib64/python3.7/site-packages/newrelic/hooks/framework_django.py", line 944, in wrapper File "/var/app/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 101, in dispatch File "./netbox/views.py", line 193, in get File "/var/app/venv/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method File "./utilities/querysets.py", line 22, in restrict File "/var/app/venv/lib/python3.7/site-packages/django/utils/functional.py", line 240, in inner File "/var/app/venv/lib/python3.7/site-packages/django/utils/functional.py", line 376, in _setup File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 23, in <lambda> File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 11, in get_user File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 174, in get_user File "/var/app/venv/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 58, in _get_user_session_key File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 65, in __getitem__ File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 220, in _get_session File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 44, in load File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 122, in decode File "/var/app/venv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 126, in _legacy_decode File "/usr/lib64/python3.7/base64.py", line 87, in b64decode ``` We use New Relic for APM monitoring so ignore the intermixed newrelic packages, this issue happens without new relic as well. This seems to be user and browser specific. It doesn't always happen, it doesn't happen to the same users, and usually, if the user switches web browsers they are able to connect to NetBox. I have been able to reproduce this issue occasionally by upgrading minor versions of NetBox (i.e. 2.9.7 -> 2.9.8) a quick fix although a big hammer fix is to truncate the django_session table, but this seems drastic. This happens often enough I feel it is worth reporting. ### Steps to Reproduce 1. Launch a web browser and connect to NetBox, this only happens occasionally <!-- What did you expect to happen? --> ### Expected Behavior The NetBox UI is displayed <!-- What happened instead? --> ### Observed Behavior The user is presented with the error captured above
adam closed this issue 2025-12-29 18:34:33 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 25, 2020):

This looks like Django issue #31592. If you don't believe that applies, please determine a set of steps that will reliably reproduce this issue on a new installation so that it can be investigated.

@jeremystretch commented on GitHub (Nov 25, 2020): This looks like [Django issue #31592](https://code.djangoproject.com/ticket/31592). If you don't believe that applies, please determine a set of steps that will reliably reproduce this issue on a new installation so that it can be investigated.
Author
Owner

@jeremystretch commented on GitHub (Dec 2, 2020):

@nniehoff can you provide an update please?

@jeremystretch commented on GitHub (Dec 2, 2020): @nniehoff can you provide an update please?
Author
Owner

@nniehoff commented on GitHub (Dec 2, 2020):

That bug has the same symptom but not the same cause I'm not downgrading django, in fact I would guess most of the time I'm not touching django with a minor version update of netbox. The workaround in the bug seems slightly more sane than truncating a table in postgres:

from django.contrib.sessions.models import Session
Session.objects.all().delete()

so that is worth noting. The set of steps to reproduce this in my environment is as described above. Perform a minor version update of NetBox and post upgrade some users some times might hit the error. It is not easy to reproduce but I have seen it now with 2.9.3-> 2.9.4, 2.9.4->2.9.7, 2.9.7->2.9.8, and 2.9.8 -> 2.9.9. We may have seen it before then too but considered it one a one off issue. I think it's good to have this issue document a workaround in case anyone else runs into this problem and would be curious if anyone else does hit this.

@nniehoff commented on GitHub (Dec 2, 2020): That bug has the same symptom but not the same cause I'm not downgrading django, in fact I would guess most of the time I'm not touching django with a minor version update of netbox. The workaround in the bug seems slightly more sane than truncating a table in postgres: ``` from django.contrib.sessions.models import Session Session.objects.all().delete() ``` so that is worth noting. The set of steps to reproduce this in my environment is as described above. Perform a minor version update of NetBox and post upgrade some users some times might hit the error. It is not easy to reproduce but I have seen it now with 2.9.3-> 2.9.4, 2.9.4->2.9.7, 2.9.7->2.9.8, and 2.9.8 -> 2.9.9. We may have seen it before then too but considered it one a one off issue. I think it's good to have this issue document a workaround in case anyone else runs into this problem and would be curious if anyone else does hit this.
Author
Owner

@candlerb commented on GitHub (Dec 3, 2020):

I don't know if the underlying cause is the same, but a reproducible way to generate the same error is to login from a browser, then change the SECRET_KEY in configuration.py and restart netbox, then browse back to netbox from the same browser.

Described further in this google group thread, which includes some analysis of backtrace.

@candlerb commented on GitHub (Dec 3, 2020): I don't know if the underlying cause is the same, but a reproducible way to generate the same error is to login from a browser, then change the SECRET_KEY in configuration.py and restart netbox, then browse back to netbox from the same browser. Described further in [this google group thread](https://groups.google.com/g/netbox-discuss/c/SlAhOsurJuk), which includes some analysis of backtrace.
Author
Owner

@nniehoff commented on GitHub (Dec 9, 2020):

@candlerb you may be on to something here, I thought our CI deployment was setting the SECRET_KEY to a known secret, apparently, it's not and in our environment we have it defaulting to pw_gen(50) I'm surprised it's not more repeatable but at least this might explain things. I have addressed the issue and will now use the same SECRET_KEY between rebuilds.

@nniehoff commented on GitHub (Dec 9, 2020): @candlerb you may be on to something here, I *thought* our CI deployment was setting the `SECRET_KEY` to a known secret, apparently, it's not and in our environment we have it defaulting to `pw_gen(50)` I'm surprised it's not more repeatable but at least this might explain things. I have addressed the issue and will now use the same `SECRET_KEY` between rebuilds.
Author
Owner

@jeremystretch commented on GitHub (Dec 15, 2020):

@nniehoff can you confirm that this issue is resolved?

@jeremystretch commented on GitHub (Dec 15, 2020): @nniehoff can you confirm that this issue is resolved?
Author
Owner

@nniehoff commented on GitHub (Dec 18, 2020):

I am planning on upgrading to 2.9.11 in 2021 and should be able to confirm it then.

@nniehoff commented on GitHub (Dec 18, 2020): I am planning on upgrading to 2.9.11 in 2021 and should be able to confirm it then.
Author
Owner

@jeremystretch commented on GitHub (Dec 18, 2020):

Ok, I'm going to close out this issue in the meantime. Please comment here if you continue running into the problem.

@jeremystretch commented on GitHub (Dec 18, 2020): Ok, I'm going to close out this issue in the meantime. Please comment here if you continue running into the problem.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4306