WebFaction
Community site: login faq

Hi,

I'm trying to create an app using Django. I'm getting the UnicodeEncodeError, "Caught UnicodeEncodeError while rendering: 'ascii' codec can't encode character u'u2122' in position 9: ordinal not in range(128)", and was wondering if anyone knew what the fix is.

Thanks a lot.

EDIT: Traceback:

Environment:

Request Method: POST
Request URL: http://shopperspoll.webfactional.com/search/results/p=1/

Django Version: 1.3
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'shopperspoll.polls',
 'shopperspoll.search',
 'django_facebook',
 'django.contrib.admin',
 'photologue']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Template error:
In template /home/shopperspoll/webapps/django/shopperspoll/mytemplates/search/results.html, error at line 88
   Caught UnicodeEncodeError while rendering: 'ascii' codec can't encode character u'\u2122' in position 9: ordinal not in range(128)
   78 :

   79 :     {% if previousPage %}

   80 :         <div class="page_navigation_previous">

   81 :         <a href="/search/results/p={{ previousPage }}w={{ keyword }}/"><< Previous Page</a>&nbsp|&nbsp

   82 :         </div>

   83 :     {% endif %}

   84 :

   85 :     </div>

   86 :

   87 :     <div class="clear"></div>

   88 :      {% for i in results %}

   89 :         <div id="item_number">

   90 :     {% if forloop.counter0 == 0 %}

   91 :     {{itemNos.0}}.

   92 :     {% endif %}

   93 :     {% if forloop.counter0 == 1 %}

   94 :     {{itemNos.1}}.

   95 :     {% endif %}

   96 :     {% if forloop.counter0 == 2 %}

   97 :     {{itemNos.2}}.

   98 :     {% endif %}

Traceback:
File "/home/shopperspoll/webapps/django/lib/python2.7/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/views/decorators/csrf.py" in wrapped_view
  39.         resp = view_func(*args, **kwargs)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/views/decorators/csrf.py" in wrapped_view
  52.         return view_func(*args, **kwargs)
File "/home/shopperspoll/webapps/django/shopperspoll/search/views.py" in results
  286.     return render_to_response('search/results.html', {'userID':userID, 'results':listOfItems, 'totalItems':totalItems, 'totalPages':totalPages, 'pageNo':newPageNo, 'previousPage':previousPage, 'itemNos':itemNos, 'keyword':searchWord}, context)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/template/loader.py" in render_to_string
  188.         return t.render(context_instance)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/template/base.py" in render
  123.             return self._render(context)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/template/base.py" in _render
  117.         return self.nodelist.render(context)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/template/base.py" in render
  744.                 bits.append(self.render_node(node, context))
File "/home/shopperspoll/webapps/django/lib/python2.7/django/template/debug.py" in render_node
  73.             result = node.render(context)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/template/defaulttags.py" in render
  227.                 nodelist.append(node.render(context))
File "/home/shopperspoll/webapps/django/lib/python2.7/django/template/debug.py" in render
  92.             output = force_unicode(output)
File "/home/shopperspoll/webapps/django/lib/python2.7/django/utils/encoding.py" in force_unicode
  74.                     s = unicode(str(s), encoding, errors)

Exception Type: TemplateSyntaxError at /search/results/p=1/
Exception Value: Caught UnicodeEncodeError while rendering: 'ascii' codec can't encode character u'\u2122' in position 9: ordinal not in range(128)

asked 02 Jun '11, 22:52

iman453
491727
accept rate: 0%

edited 17 Aug '12, 17:34

seanf
12.2k42136

Visiting the URL shows a API error, but that is a GET request. This looks like a POST request, what is getting POSTed? You can use the Django debug toolbar to get more info about the POST and other variables that might be involved, http://docs.webfaction.com/software/django/troubleshooting.html#using-the-django-debug-toolbar

Also another strange thing I see is the '=' in the URL, normally these must be used at the end of a URL to separate query strings,

http://en.wikipedia.org/wiki/Query_string

Is it possible for you to supply some of the urls.py and views.py files without exposing to much info?

(02 Jun '11, 23:36) johns

Um, basically I'm trying to play around with the Amazon API. When I search for Java, one of the results has the trademark symbol, which is being passed and is causing problems. Django templates can handle unicode by default right? Till the point this error shows up I'm not really storing stuff in my database, so I don't think it should be a database configuration problem.

(03 Jun '11, 17:07) iman453

Django should handle unicode by default, and I personally have used POST requests with Chinese in the past without difficulty.

The best thing to do at this point would be to reduce this error into a very simple test-case and then see if the Django community can provide any insight as to what is causing the issue.

(03 Jun '11, 21:44) ryans ♦♦

That part of the error alone is not enough to fix the issue.

We need the entire traceback. And possibly parts of the failing code.

permanent link

answered 02 Jun '11, 23:00

johns
5.4k412
accept rate: 23%

edited 03 Jun '11, 17:15

seanf
12.2k42136

Thank you for your reply. I've edited my question with the entire traceback.

(02 Jun '11, 23:20) iman453
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×108
×7

question asked: 02 Jun '11, 22:52

question was seen: 5,636 times

last updated: 17 Aug '12, 17:34

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM