[GH-ISSUE #565] 500 error after upgrading: 'SessionStore' object has no attribute '_session_cache' due to binascii.Error: Incorrect padding #360

Closed
opened 2026-03-01 14:42:50 +03:00 by kerem · 7 comments
Owner

Originally created by @M4RC02U1F4A4 on GitHub (Dec 3, 2020).
Original GitHub issue: https://github.com/ArchiveBox/ArchiveBox/issues/565

Describe the bug

After update from nikisweeting/archivebox to archivebox/archivebox i get Server Error (500) when using nginx
If i try to use the IP and http everythings works

Screenshots or log output

Archivebox LOG

[i] [2020-12-03 08:09:35] ArchiveBox v0.4.24: archivebox server 0.0.0.0:8000
> /data

[+] Starting ArchiveBox webserver...
Hint: The admin username is marco

Performing system checks...

System check identified no issues (0 silenced).
December 03, 2020 - 08:09:36
Django version 3.0.8, using settings 'core.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[03/Dec/2020 08:10:25] "GET / HTTP/1.0" 500 145

NGINX conf

server {
        listen 80;
        server_name archivebox.saturn.local;
        return 301 https://archivebox.saturn.local$request_uri;
}

server {
        listen 443 ssl;
        server_name archivebox.saturn.local;

        ssl_certificate /etc/nginx/ssl/cert.crt;
        ssl_certificate_key /etc/nginx/ssl/key.key;

        location / {
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header HOST $host:$server_port;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://172.18.10.22:8000;
        }

}

Software versions

  • OS: Unraid 6.8.3
  • ArchiveBox version: v0.4.24
Originally created by @M4RC02U1F4A4 on GitHub (Dec 3, 2020). Original GitHub issue: https://github.com/ArchiveBox/ArchiveBox/issues/565 #### Describe the bug After update from nikisweeting/archivebox to archivebox/archivebox i get Server Error (500) when using nginx If i try to use the IP and http everythings works #### Screenshots or log output Archivebox LOG ``` [i] [2020-12-03 08:09:35] ArchiveBox v0.4.24: archivebox server 0.0.0.0:8000 > /data [+] Starting ArchiveBox webserver... Hint: The admin username is marco Performing system checks... System check identified no issues (0 silenced). December 03, 2020 - 08:09:36 Django version 3.0.8, using settings 'core.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C. [03/Dec/2020 08:10:25] "GET / HTTP/1.0" 500 145 ``` NGINX conf ``` server { listen 80; server_name archivebox.saturn.local; return 301 https://archivebox.saturn.local$request_uri; } server { listen 443 ssl; server_name archivebox.saturn.local; ssl_certificate /etc/nginx/ssl/cert.crt; ssl_certificate_key /etc/nginx/ssl/key.key; location / { proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header HOST $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://172.18.10.22:8000; } } ``` #### Software versions - OS: Unraid 6.8.3 - ArchiveBox version: v0.4.24
kerem 2026-03-01 14:42:50 +03:00
Author
Owner

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

Can you try launching the server with archivebox server --debug 0.0.0.0:8000 and posting the error output you see.

<!-- gh-comment-id:737770697 --> @pirate commented on GitHub (Dec 3, 2020): Can you try launching the server with `archivebox server --debug 0.0.0.0:8000` and posting the error output you see.
Author
Owner

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

[i] [2020-12-03 09:15:59] ArchiveBox v0.4.24: archivebox server --debug 0.0.0.0:8000
> /data

[+] Starting ArchiveBox webserver...
Hint: The admin username is marco

Performing system checks...

System check identified no issues (0 silenced).
December 03, 2020 - 09:16:00
Django version 3.0.8, using settings 'core.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 199, in _get_session
return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/app/archivebox/core/views.py", line 32, in get
if request.user.is_authenticated:
File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 224, in inner
self._setup()
File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 360, in _setup
self._wrapped = self._setupfunc()
File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/middleware.py", line 24, in <lambda>
request.user = SimpleLazyObject(lambda: get_user(request))
File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/middleware.py", line 12, in get_user
request._cached_user = auth.get_user(request)
File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 173, in get_user
user_id = _get_user_session_key(request)
File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 58, in _get_user_session_key
return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 64, in __getitem__
return self._session[key]
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session
self._session_cache = self.load()
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 44, in load
return self.decode(s.session_data) if s else {}
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode
encoded_data = base64.b64decode(session_data.encode('ascii'))
File "/usr/local/lib/python3.8/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
Internal Server Error: /
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 199, in _get_session
return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/site-packages/django/utils/deprecation.py", line 96, in __call__
response = self.process_response(request, response)
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/middleware.py", line 47, in process_response
if request.session.get_expire_at_browser_close():
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 291, in get_expire_at_browser_close
if self.get('_session_expiry') is None:
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 75, in get
return self._session.get(key, default)
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session
self._session_cache = self.load()
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 44, in load
return self.decode(s.session_data) if s else {}
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode
encoded_data = base64.b64decode(session_data.encode('ascii'))
File "/usr/local/lib/python3.8/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
[03/Dec/2020 09:17:09] "GET / HTTP/1.1" 500 87970
Internal Server Error: /favicon.ico
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 199, in _get_session
return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/site-packages/django/utils/deprecation.py", line 96, in __call__
response = self.process_response(request, response)
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/middleware.py", line 47, in process_response
if request.session.get_expire_at_browser_close():
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 291, in get_expire_at_browser_close
if self.get('_session_expiry') is None:
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 75, in get
return self._session.get(key, default)
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session
self._session_cache = self.load()
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 44, in load
return self.decode(s.session_data) if s else {}
File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode
encoded_data = base64.b64decode(session_data.encode('ascii'))
File "/usr/local/lib/python3.8/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
<!-- gh-comment-id:737775665 --> @M4RC02U1F4A4 commented on GitHub (Dec 3, 2020): ``` [i] [2020-12-03 09:15:59] ArchiveBox v0.4.24: archivebox server --debug 0.0.0.0:8000 > /data [+] Starting ArchiveBox webserver... Hint: The admin username is marco Performing system checks... System check identified no issues (0 silenced). December 03, 2020 - 09:16:00 Django version 3.0.8, using settings 'core.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C. Internal Server Error: / Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 199, in _get_session return self._session_cache AttributeError: 'SessionStore' object has no attribute '_session_cache' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "/app/archivebox/core/views.py", line 32, in get if request.user.is_authenticated: File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 224, in inner self._setup() File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 360, in _setup self._wrapped = self._setupfunc() File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/middleware.py", line 24, in <lambda> request.user = SimpleLazyObject(lambda: get_user(request)) File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/middleware.py", line 12, in get_user request._cached_user = auth.get_user(request) File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 173, in get_user user_id = _get_user_session_key(request) File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 58, in _get_user_session_key return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY]) File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 64, in __getitem__ return self._session[key] File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session self._session_cache = self.load() File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 44, in load return self.decode(s.session_data) if s else {} File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode encoded_data = base64.b64decode(session_data.encode('ascii')) File "/usr/local/lib/python3.8/base64.py", line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Incorrect padding Internal Server Error: / Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 199, in _get_session return self._session_cache AttributeError: 'SessionStore' object has no attribute '_session_cache' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/usr/local/lib/python3.8/site-packages/django/utils/deprecation.py", line 96, in __call__ response = self.process_response(request, response) File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/middleware.py", line 47, in process_response if request.session.get_expire_at_browser_close(): File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 291, in get_expire_at_browser_close if self.get('_session_expiry') is None: File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 75, in get return self._session.get(key, default) File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session self._session_cache = self.load() File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 44, in load return self.decode(s.session_data) if s else {} File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode encoded_data = base64.b64decode(session_data.encode('ascii')) File "/usr/local/lib/python3.8/base64.py", line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Incorrect padding [03/Dec/2020 09:17:09] "GET / HTTP/1.1" 500 87970 Internal Server Error: /favicon.ico Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 199, in _get_session return self._session_cache AttributeError: 'SessionStore' object has no attribute '_session_cache' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/usr/local/lib/python3.8/site-packages/django/utils/deprecation.py", line 96, in __call__ response = self.process_response(request, response) File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/middleware.py", line 47, in process_response if request.session.get_expire_at_browser_close(): File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 291, in get_expire_at_browser_close if self.get('_session_expiry') is None: File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 75, in get return self._session.get(key, default) File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session self._session_cache = self.load() File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 44, in load return self.decode(s.session_data) if s else {} File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode encoded_data = base64.b64decode(session_data.encode('ascii')) File "/usr/local/lib/python3.8/base64.py", line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Incorrect padding ```
Author
Owner

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

Oh you need to run archivebox init whenever you update the container, it's just missing some migrations I think.

<!-- gh-comment-id:737777912 --> @pirate commented on GitHub (Dec 3, 2020): Oh you need to run `archivebox init` whenever you update the container, it's just missing some migrations I think.
Author
Owner

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

Oh you need to run archivebox init whenever you update the container, it's just missing some migrations I think.

I did this when I changed Docker hub repository
However I tried again and I always get Server Error (500)

<!-- gh-comment-id:737779986 --> @M4RC02U1F4A4 commented on GitHub (Dec 3, 2020): > > > Oh you need to run `archivebox init` whenever you update the container, it's just missing some migrations I think. I did this when I changed Docker hub repository However I tried again and I always get Server Error (500)
Author
Owner

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

Did you at any point run the :latest version from docker before downgrading back to v0.4.24? That might explain it.

You can try fixing it by running this in archivebox shell:

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

You should also clear your browser cookies and cache for https://archivebox.saturn.local so that it doesn't resend the bad token to the backend, then try logging in again.

This error appears to be specific to Django 3.0.6, and is fixed with 3.1 which we will release with the next ArchiveBox v0.5.0 version in a few weeks, so as long as we get it working for you I'm not too worried about it affecting other users.

https://stackoverflow.com/questions/63546429/binascii-error-incorrect-padding-in-python-django
https://code.djangoproject.com/ticket/31592

<!-- gh-comment-id:737785819 --> @pirate commented on GitHub (Dec 3, 2020): Did you at any point run the `:latest` version from docker before downgrading back to `v0.4.24`? That might explain it. You can try fixing it by running this in `archivebox shell`: ```python from django.contrib.sessions.models import Session Session.objects.all().delete() ``` You should also clear your browser cookies and cache for https://archivebox.saturn.local so that it doesn't resend the bad token to the backend, then try logging in again. This error appears to be specific to Django 3.0.6, and is fixed with 3.1 which we will release with the next ArchiveBox v0.5.0 version in a few weeks, so as long as we get it working for you I'm not too worried about it affecting other users. https://stackoverflow.com/questions/63546429/binascii-error-incorrect-padding-in-python-django https://code.djangoproject.com/ticket/31592
Author
Owner

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

Did you at any point run the :latest version from docker before downgrading back to v0.4.24? That might explain it.

Not at any time, but always, the image is automatically updated to the image on Docker Hub marked as latest

Cleaned cache and cookies and now it works, thanks

<!-- gh-comment-id:737821610 --> @M4RC02U1F4A4 commented on GitHub (Dec 3, 2020): > > Did you at any point run the `:latest` version from docker before downgrading back to `v0.4.24`? That might explain it. > Not at any time, but always, the image is automatically updated to the image on Docker Hub marked as latest Cleaned cache and cookies and now it works, thanks
Author
Owner

@BlankerL commented on GitHub (Dec 4, 2020):

Cleaned cache and cookies and now it works, thanks

Thank you for the solution, worked on my browser as well.

<!-- gh-comment-id:738790895 --> @BlankerL commented on GitHub (Dec 4, 2020): > Cleaned cache and cookies and now it works, thanks Thank you for the solution, worked on my browser as well.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ArchiveBox#360
No description provided.