前提・実現したいこと
現在、Djangoで初のWeb開発をしています。
そこでデバッグツールバーを表示させようと思い、pipで、django-debug-toolbarを導入してからsettings.pyやurls.pyをいじっていました。
settings.pyのMIDDLEWAREに'debug_toolbar.middleware.DebugToolbarMiddleware', を加えると以下のエラーが発生してしまいました。
発生している問題・エラーメッセージ
binascii.Error: Invalid base64-encoded string: number of data characters (213) cannot be 1 more than a multiple of 4
このエラーを調べてみると、データを4文字区切りにしないとダメなようなのですが、どこをどのように区切ればいいのかわかりません。
ご教示してもらえるとありがたいです。
問題が発生するまでの流れ
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', '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', + 'debug_toolbar.middleware.DebugToolbarMiddleware', # Deubg tool bar ]
+の行を加えるとエラーが発生します。
エラーの全貌
Internal Server Error: / Traceback (most recent call last): File "/Users/mizutanikizashi/venv/lib/python3.9/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 "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 145, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 143, in _get_response response = response.render() File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/template/response.py", line 105, in render self.content = self.rendered_content File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/template/response.py", line 83, in rendered_content return template.render(context, self._request) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render return self.template.render(context) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/template/base.py", line 171, in render return self._render(context) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/test/utils.py", line 94, in instrumented_test_render template_rendered.send(sender=self, template=self, context=context) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 173, in send return [ File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 174, in <listcomp> (receiver, receiver(signal=self, sender=sender, **named)) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/debug_toolbar/panels/templates/panel.py", line 103, in _store_template_info if isinstance(value, http.HttpRequest): File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/utils/functional.py", line 224, in inner self._setup() File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/utils/functional.py", line 360, in _setup self._wrapped = self._setupfunc() File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/auth/middleware.py", line 24, in <lambda> request.user = SimpleLazyObject(lambda: get_user(request)) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/auth/middleware.py", line 12, in get_user request._cached_user = auth.get_user(request) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/auth/__init__.py", line 173, in get_user user_id = _get_user_session_key(request) File "/Users/mizutanikizashi/venv/lib/python3.9/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 "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 64, in __getitem__ return self._session[key] File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session self._session_cache = self.load() File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/db.py", line 44, in load return self.decode(s.session_data) if s else {} File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode encoded_data = base64.b64decode(session_data.encode('ascii')) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/base64.py", line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Invalid base64-encoded string: number of data characters (213) cannot be 1 more than a multiple of 4 Internal Server Error: / Traceback (most recent call last): File "/Users/mizutanikizashi/venv/lib/python3.9/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 "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/debug_toolbar/middleware.py", line 67, in __call__ panel.generate_stats(request, response) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/debug_toolbar/panels/request.py", line 57, in generate_stats for k in sorted(request.session.keys()) File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 135, in keys return self._session.keys() File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 204, in _get_session self._session_cache = self.load() File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/db.py", line 44, in load return self.decode(s.session_data) if s else {} File "/Users/mizutanikizashi/venv/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 110, in decode encoded_data = base64.b64decode(session_data.encode('ascii')) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/base64.py", line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Invalid base64-encoded string: number of data characters (213) cannot be 1 more than a multiple of 4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/30 01:24
2021/01/30 01:28