Dr. Younes Henni
Dr. Younes Henni

Reputation: 1771

Memcache status not working for Django 1.11 and Python 3.6

I installed memcached for my django project (Django 1.11 and Python 3.6). When I add the memcached_status to my installed apps in settings.py, I get this error when I try to open the Django admin page:

Internal Server Error: /admin/
Traceback (most recent call last):
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/core/handlers/base.py", line 217, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/core/handlers/base.py", line 215, in _get_response
response = response.render()
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/response.py", line 107, in render
self.content = self.rendered_content
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/response.py", line 84, in rendered_content
content = template.render(context, self._request)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/backends/django.py", line 66, in render
return self.template.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 207, in render
return self._render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/loader_tags.py", line 177, in render
return compiled_parent._render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/loader_tags.py", line 177, in render
return compiled_parent._render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/loader_tags.py", line 177, in render
return compiled_parent._render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/loader_tags.py", line 72, in render
result = block.nodelist.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/defaulttags.py", line 322, in render
return nodelist.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/defaulttags.py", line 216, in render
nodelist.append(node.render_annotated(context))
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/defaulttags.py", line 216, in render
nodelist.append(node.render_annotated(context))
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 1040, in render
output = self.filter_expression.resolve(context)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/base.py", line 736, in resolve
new_obj = func(obj, *arg_vals)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/memcache_status/templatetags/memcache_status_tags.py", line 
106, in prettyname
return ' '.join([word.capitalize() for word in name.split('_')])
TypeError: a bytes-like object is required, not 'str'

In their github repo they say that I only need to add memchache_status to my installed apps in settings.py and it will work. Did anyone had the same issue ? If yes how should I install properly the memchached status for my Django admin page.

Upvotes: 2

Views: 653

Answers (1)

mhawke
mhawke

Reputation: 87134

Updated

I suspect that you have also installed python3-memcached (now deprecated, see README) in which case that might have overwritten your python-memcached installation (which now supports Python 2 & 3). If so, you need to remove both python3-memcached andpython-memcached then reinstall the latter, version >= 1.58.


You need to upgrade python-memcache to the latest version, currently 1.58.

This package interacts with your memcached server to extract the stats collected by it. Earlier versions of the package did not decode the incoming stats data (in particular the keys) into Python 3 str type (i.e. unicode), and just passed on a bytes string to the memcached_status prettyname filter - which assumes a str object.

Upvotes: 2

Related Questions