I am running a Django app on AWS Elastic Beanstalk but Django debug toolbar is causing the following error:
Traceback (most recent call last):
File "/opt/python/run/venv/lib/python3.4/site-packages/django/core/handlers/base.py", line 235, in get_response
response = middleware_method(request, response)
File "/opt/python/run/venv/lib/python3.4/site-packages/debug_toolbar/middleware.py", line 123, in process_response
response.content = insert_before.join(bits)
File "/opt/python/run/venv/lib/python3.4/site-packages/django/http/response.py", line 315, in content
value = self.make_bytes(value)
File "/opt/python/run/venv/lib/python3.4/site-packages/django/http/response.py", line 235, in make_bytes
return bytes(value.encode(self.charset))
UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcc3' in position 142917: surrogates not allowed
I did not have this problem locally or when running my django app on an AWS EC2 instance where I setup nginx and gunicorn myself. Something about Elastic Beanstalk? Maybe that it's apache?
Some details about my configuration:
Versions
Same locally as well as on AWS EBS
Python 3.4.3
Django 1.9.7
Django Toolbar 1.5
Django Settings
The following are pieces of my django settings where I activate the toolbar
INSTALLED_APPS = [
'compare.apps.CompareConfig',
'search.apps.SearchConfig',
'profile.apps.ProfileConfig',
'common.apps.CommonConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_toolbar',
]
(I tried moving django_toolbar
further up in the list of installed apps but it didn't help)
MIDDLEWARE_CLASSES = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'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',
]
DEBUG_TOOLBAR_PATCH_SETTINGS = False
def custom_show_toolbar(request):
return True # Always show toolbar, for example purposes only.
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': custom_show_toolbar,
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
And in my root url conf file I have
urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))]
There was some other SO (can't find link now) that mentioned something about adding utf-8
to one of the language or USE_***
parameters but I tried it and didn't help - but perhaps I didn't do it correctly also.
I really love the Django debug toolbar, would greatly appreciate being able to resolve this.
Any ideas?
Thanks!