First time here? Check out the FAQ!
2

UnicodeEncodeError at /questions/ask/
 

Hello, I am using most recent version of askbot from github (askbot-devel). When I am trying to create a new question with unicode letters in title I get following error:

UnicodeEncodeError at /questions/ask/
'ascii' codec can't encode characters in position 3-5: ordinal not in range(128)


Environment:


Request Method: POST
Request URL: http://.../questions/ask/

Django Version: 1.5.2
Python Version: 2.7.3
Installed Applications:
('longerusername',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.humanize',
 'django.contrib.sitemaps',
 'django.contrib.messages',
 'compressor',
 'askbot',
 'askbot.deps.django_authopenid',
 'south',
 'askbot.deps.livesettings',
 'keyedcache',
 'robots',
 'django_countries',
 'djcelery',
 'djkombu',
 'followit',
 'tinymce',
 'group_messaging')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
 'askbot.middleware.forum_mode.ForumModeMiddleware',
 'askbot.middleware.cancel.CancelActionMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'askbot.middleware.view_log.ViewLogMiddleware',
 'askbot.middleware.spaceless.SpacelessMiddleware')


Traceback:
File "/home/dev/askbot/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/dev/askbot/env/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/dev/askbot/env/src/askbot/askbot/utils/decorators.py" in wrapper
  136.             return view_func(request, *args, **kwargs)
File "/home/dev/askbot/env/src/askbot/askbot/utils/decorators.py" in wrapper
  231.             return view_func(request, *args, **kwargs)
File "/home/dev/askbot/env/src/askbot/askbot/views/writers.py" in ask
  259.                         language=language
File "/home/dev/askbot/env/src/askbot/askbot/models/__init__.py" in user_post_question
  1759.                                     language=language
File "/home/dev/askbot/env/src/askbot/askbot/models/question.py" in create_new
  172.         parse_results = question.parse_and_save(author=author, is_private=is_private)
File "/home/dev/askbot/env/src/askbot/askbot/models/post.py" in parse_and_save
  507.         data = self.parse_post_text()
File "/home/dev/askbot/env/src/askbot/askbot/models/post.py" in parse_post_text
  439.         text = text_converter(self.text)
File "/home/dev/askbot/env/src/askbot/askbot/utils/markup.py" in markdown_input_converter
  205.     text = urlize_html(text)
File "/home/dev/askbot/env/src/askbot/askbot/utils/html.py" in urlize_html
  70.     soup = BeautifulSoup(html, 'html5lib')
File "/home/dev/askbot/env/local/lib/python2.7/site-packages/bs4/__init__.py" in __init__
  167.             if os.path.exists(markup):
File "/home/dev/askbot/env/lib/python2.7/genericpath.py" in exists
  18.         os.stat(path)

Exception Type: UnicodeEncodeError at /questions/ask/
Exception Value: 'ascii' codec can't encode characters in position 3-5: ordinal not in range(128)

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
idavydov's avatar
21
idavydov
asked 11 years ago

Comments

Is this in the production setup?

Evgeny's avatar Evgeny (11 years ago)

Evgeny, actually I've tried first to install stable version 0.7.43. But python manage.py migrate askbot failed on both mysql and postgres. Then I tried git latest version and migrate passed succesfully but I got unicode error.

idavydov's avatar idavydov (11 years ago)

Evgeny, I have the same problem with cyrillic. i.e.: I add simple test question (see screenhot: http://my.jetscreenshot.com/5516/20131007-uerk-28kb.jpg) and get the following result with "UnicodeEncodeError at /questions/ask/" error: http://my.jetscreenshot.com/5516/20131007-r9l1-159kb.jpg I am using the completely new version of Askbot (0.7.49), django 1.5.4 Error appears when I add russian text from keybord to descripton of the question filed or to the answer. Error never apper when I copy-paste russian text from UTF-8 website like http://wikipedia.org That is all quite strange I would be very thankful, if you coul tell what is the reason of it or any idea about this one. (parameter ALLOW_UNICODE_SLUGS is set to True) UPDATED: the reason was - that I used it as gunicorn, when I launched it as runserver - it started to work without any errors

shurikanet's avatar shurikanet (11 years ago)
see more comments

2 Answers

0

I believe it the cache! For me it started to work when I disabled Memcached!

You can read my answer to my own quiestion here: http://askbot.org/en/question/14688/a...

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Tvartom's avatar
31
Tvartom
answered 8 years ago
link

Comments

see more comments
0

The issue is that the encoding set in your server python process is unable to encode a specific unicode string.

Details can be found here http://blog.dscpl.com.au/2014/09/sett....

To solve this, set the following locale related environment variables to be used in your python server process:

LANG='en_US.UTF-8'
LC_ALL='en_US.UTF-8'

For example uwsgi takes the following (in the .ini file):

env = LC_ALL='en_US.UTF-8' #I find this sufficient

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 8 years ago
link

Comments

see more comments