Ask Your Question

Askbot crashing on questions with åäö

asked 2016-06-13 16:58:34 -0600

Tvartom gravatar image

Hi! Iv'e a clean intstall of Askbot on a CentOS-server with uWsgi. It's behind an Nginx (on an other server). Evrything works fine. Can create users, ask questions etc. Until I put a non ascii-character (Swedish åäö) in the title of a question.

The question is stored properly, And is possible to read on the /question/X/Testfrågan-url. I is also stored correctly in the databas in the askbot_post-table.

But I get a UnicodeDecodeError on /questions/ or /users/X/User for the user who has written the question. The UnicodeDecodeError complains about the title.

The string that could not be encoded/decoded was: estfr��gan<

I have tried with different setting for ALLOW_UNICODE_SLUGS and ASKBOT_TRANSLATE_URL, and droped the database and retried. Database is UTF-8, and so is the DATABASES.TEST_CHARSET, DATABASES.TEST_COLLATION.

What do I do wrong? How can I fix this?

CentOS 7.2.1511
Askbot: 0.10.0
Django: 1.8.13
Python: 2.7.5
PostgreSQL: 9.3


File "/var/www/askbot/lib/python2.7/site-packages/django/core/handlers/" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/askbot/lib/python2.7/site-packages/askbot/views/" in questions
  287.         return render(request, 'main_page.html', template_data)
File "/var/www/askbot/lib/python2.7/site-packages/django/" in render
  67.             template_name, context, request=request, using=using)
File "/var/www/askbot/lib/python2.7/site-packages/django/template/" in render_to_string
  99.         return template.render(context, request)
File "/var/www/askbot/lib/python2.7/site-packages/askbot/skins/" in render
  86.         return self.template.render(context)
File "/var/www/askbot/lib/python2.7/site-packages/coffin/template/" in render
  55.         return super(Template, self).render(**context)
File "/var/www/askbot/lib/python2.7/site-packages/jinja2/" in render
  989.         return self.environment.handle_exception(exc_info, True)
File "/var/www/askbot/lib/python2.7/site-packages/jinja2/" in handle_exception
  754.         reraise(exc_type, exc_value, tb)
File "/var/www/askbot/lib/python2.7/site-packages/askbot/templates/main_page.html" in top-level template code
  2. {% import "macros.html" as macros %}
File "/var/www/askbot/lib/python2.7/site-packages/askbot/templates/two_column_body.html" in top-level template code
  1. {% extends "base.html" %}
File "/var/www/askbot/lib/python2.7/site-packages/askbot/templates/base.html" in top-level template code
  46.             {% block body %}
File "/var/www/askbot/lib/python2.7/site-packages/askbot/templates/two_column_body.html" in block "body"
  5.     {% block content%}
File "/var/www/askbot/lib/python2.7/site-packages/askbot/templates/main_page.html" in block "content"
  21.         {% include "main_page/questions_loop.html" %}
File "/var/www/askbot/lib/python2.7/site-packages/askbot/templates/main_page/questions_loop.html" in top-level template code
  6.         {{ thread.get_summary_html(search_state=search_state, visitor = request.user) }}

Exception Type: UnicodeDecodeError at /questions/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 1064: ordinal not in range(128)
edit retag flag offensive close merge delete


Why not update Python to 2.7.11 or 2.7.12?

slelievre gravatar imageslelievre ( 2016-07-13 02:25:13 -0600 )edit

Thanks for your suggest! I uppgraded to 2.7.12. Still no success! Anyone having any idea? Should I try Python 3.3?

Tvartom gravatar imageTvartom ( 2016-12-01 19:46:30 -0600 )edit

2 answers

Sort by » oldest newest most voted

answered 2016-12-20 13:45:06 -0600

Evgeny gravatar image

updated 2016-12-21 06:49:45 -0600

What seems to fix the issue - add to

import sys
reload(sys) #this brings method setdefaultencoding

As @Tvartom suggested - this issue is seen when the django memcache caching backend is used. I find it strange how django memcached cache backend works (even after the default encoding is set to utf-8):

>>> from django.core.cache import cache
>>> cache.set('key', u'\u1537')
>>> cache.get('key')

Note that the value comes back as encoded string, not as original value.

With Redis cache (and similarly with the LocMemCache) I get what I'd expect:

>>> cache.set('key', u'\u1537')
>>> cache.get('key')

Redis cache also works irrespective of the default encoding.

Because of that I would recommend to use django-redis-cache.

edit flag offensive delete link more

answered 2016-12-01 21:02:43 -0600

Tvartom gravatar image

updated 2016-12-21 09:26:38 -0600

Finally I found a solution! The problem is memcached !

Succedded to trace down the problem to

#File:askbot/models/ Line 1678
html = self.get_cached_summary_html(visitor) or self.update_summary_html(visitor)

If I remove the "get_cached" part:

html = self.update_summary_html(visitor)

it work like a charm.

Stopped digging there, and with restored code I and stopped the memcache service, and suddenly everything worked.

edit flag offensive delete link more


@Tvartom what you are suggesting is to not cache the summary html fragments that are shown on the main page. This will make the main page load quite a bit slower.

Evgeny gravatar imageEvgeny ( 2016-12-20 13:46:15 -0600 )edit

No, I'm not suggesting to not cache this, I just told you how I did find out.

Tvartom gravatar imageTvartom ( 2016-12-21 09:26:08 -0600 )edit

Ok, thanks, it did help to pinpoint this issue to caching.

Evgeny gravatar imageEvgeny ( 2016-12-21 09:30:00 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-06-13 16:58:34 -0600

Seen: 611 times

Last updated: Dec 21 '16