Opened 5 years ago

Closed 5 years ago

#14525 closed (invalid)

Bug - exception in, etc when using unicode characters.

Reported by: yoyoma Owned by: nobody
Component: Contrib apps Version: 1.2
Severity: Keywords: messages
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


On I reported that Unicode values causes an exception when passed into (and other 3 messages methods). In my report, I erroneously suggested that a Unicode character in the URL's GET parameters would cause the exception. The following example will reproduce the exception (includes extraneous steps for the sake of completion):


# The following assumes that settings are default, except the for SQLLite3 database setting, and file path, and the installed apps setting.

# Model
class Foo(Model):
    name = models.CharField(max_length=255)

# Form
class FooForm(ModelForm):
    class Meta:
        model = Foo

# View
def create_foo(request):
    if request.method == 'POST':
        form = FooForm(request.POST)
        if form.is_valid():
            instance =
  , 'Thanks, {0}.'.format(
            return redirect('foo_thanks')
        form = FooForm()
    data = {
        'form': form,
    context = RequestContext(request, data)
    template = Template("""<html>
                <title>Bug Page</title>
                    <h1>Type ° (alt + 0176) into the name field, and hit submit.</h1>
                    <form action="" method="post" enctype="application/x-www-form-urlencoded">{% csrf_token %}
                            <button type="submit">Raise Exception</button>
    output = template.render(context)
    return HttpResponse(output)

def foo_thanks(request):
    return HttpResponse('No need to render message, as exception occurs upon creation.')


UnicodeEncodeError at /create_foo/

('ascii', u'\xb0', 0, 1, 'ordinal not in range(128)')

Request Method: 	GET
Request URL:
Django Version: 	1.3 pre-alpha SVN-14235
Exception Type: 	UnicodeEncodeError
Exception Value: 	

('ascii', u'\xb0', 0, 1, 'ordinal not in range(128)')

Exception Location: 	D:\myproject\myapp\ in create_foo, line XXX
Python Executable: 	C:\Python26\python.exe
Python Version: 	2.6.4

1) response = callback(request, *callback_args, **callback_kwargs)
2), 'Thanks, {0}.'.format(

There are only 2 steps in the traceback.

Change History (2)

comment:1 Changed 5 years ago by tobias

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I think the error might be in your code. See below:

In [4]: u'Thanks, {0}.'.format(u'°')
Out[4]: u'Thanks, \xc2\xb0.'

In [5]: 'Thanks, {0}.'.format(u'°')
UnicodeEncodeError                        Traceback (most recent call last)

/home/tobias/<ipython console> in <module>()

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

comment:2 Changed 5 years ago by Alex

  • Resolution set to invalid
  • Status changed from new to closed

tobias is correct, the stacktrace ends right at your format call. Closing as invalid since there's no bug in Django.

Note: See TracTickets for help on using tickets.
Back to Top