login community 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:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
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 Jun 02 '11 at 22:52

iman453's gravatar image

iman453
2914

edited Aug 17 '12 at 17:34

seanf's gravatar image

seanf ♦♦
56291220

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?

(Jun 02 '11 at 23:36) johns ♦♦ johns's gravatar image

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.

(Jun 03 '11 at 17:07) iman453 iman453's gravatar image

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.

(Jun 03 '11 at 21:44) ryans ♦♦ ryans's gravatar image

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.

answered Jun 02 '11 at 23:00

johns's gravatar image

johns ♦♦
340427

edited Jun 03 '11 at 17:15

seanf's gravatar image

seanf ♦♦
56291220

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

(Jun 02 '11 at 23:20) iman453 iman453's gravatar image
Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
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

Tags:

×72
×3

Asked: Jun 02 '11 at 22:52

Seen: 1,072 times

Last updated: Aug 17 '12 at 17:34

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited