Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#10905 closed (worksforme)

UnicodeEncodeError from FileUploadTests.test_unicode_file_name

Reported by: Richard Davies <richard.davies@…> Owned by: nobody
Component: File uploads/storage Version:
Severity: Keywords:
Cc: richard.davies@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Running the test suite on a clean check out of r10628, I get:

ERROR: test_unicode_file_name (regressiontests.file_uploads.tests.FileUploadTests)
Traceback (most recent call last):
  File "/home/elastic-www/test/trunk/tests/regressiontests/file_uploads/", line 67, in test_unicode_file_name
    response ='/file_uploads/unicode_name/', post_data)
  File "/home/elastic-www/test/trunk/django/test/", line 313, in post
    response = self.request(**r)
  File "/home/elastic-www/test/trunk/django/core/handlers/", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/elastic-www/test/trunk/tests/regressiontests/file_uploads/", line 64, in file_upload_unicode_name
    obj = FileModel.objects.create(testfile=uni_named_file)
  File "/home/elastic-www/test/trunk/django/db/models/", line 126, in create
    return self.get_query_set().create(**kwargs)
  File "/home/elastic-www/test/trunk/django/db/models/", line 284, in create
  File "/home/elastic-www/test/trunk/django/db/models/", line 407, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File "/home/elastic-www/test/trunk/django/db/models/", line 471, in save_base
    values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True))) for f in meta.local_fields if not isinstance(f, AutoField)]
  File "/home/elastic-www/test/trunk/django/db/models/fields/", line 191, in pre_save, file, save=False)
  File "/home/elastic-www/test/trunk/django/db/models/fields/", line 83, in save
    self._name =, content)
  File "/home/elastic-www/test/trunk/django/core/files/", line 46, in save
    name = self.get_available_name(name)
  File "/home/elastic-www/test/trunk/django/core/files/", line 68, in get_available_name
    while self.exists(name):
  File "/home/elastic-www/test/trunk/django/core/files/", line 198, in exists
    return os.path.exists(self.path(name))
  File "/lib/python2.5/", line 171, in exists
    st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 43-44: ordinal not in range(128)

My command line to run the tests was:

$ cat
$ ./ --settings=settings file_uploads

Change History (4)

comment:1 Changed 10 years ago by Richard Davies <richard.davies@…>

Version: 1.0

comment:2 Changed 10 years ago by Karen Tracey

What is your LANG set to? You are seeing a failure often seen under Apache due to an incorrect LANG setting:

I suspect you have LANG set to something like C, which results in the ascii codec being used for encoding unicode file paths passed into system calls. As the file path for that test can't be represented in ASCII, you get an error. Setting LANG to something like 'en_US.UTF-8' will cause the utf8 codec to be used for encoding file paths to bytestrings, and the test will pass.

comment:3 Changed 10 years ago by Jacob

Resolution: worksforme
Status: newclosed

See Karen's note: unicode path support only works if your filesystem does.

comment:4 Changed 7 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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