#17816: UnicodeEncodeError in Image- and FileFields -------------------------------------+------------------------------------- Reporter: andi@… | Owner: nobody Type: | Status: closed Cleanup/optimization | Version: 1.3 Component: Forms | Resolution: needsinfo Severity: Normal | Triage Stage: Keywords: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by clime7@…): I have encountered a similar problem and I'd like to add some info for this. Two things can cause unicode errors like this: 1) non-utf8 encoding returned by sys.getdefaultencoding() causes unicode errors in cases like: str(unicode_string_with_accents), i.e. whenever there is a conversion from unicode string to byte string without explicitly specifying encoding like this: str(unicode_string_with_accents.encode('utf-8')). However, ascii is default for python 2 and it shouldn't be fiddled with so this is an expected problem. 2) non-utf8 encoding returned by sys.getfilesystemencoding(). This should on the other hand really return an utf-8 encoding because otherwise you get unicode errors in cases like os.stat(unicode_string_with_accents). os module looks at filesystem encoding when trying to interpret unicode strings. And on linux file system encoding is inferred from locale of python interpretter. Specifically there should be LANG=something.utf8 in the environment. I have resolved my problem by adding "env = LANG=en_US.utf8" to my uwsgi.ini. I believe other people with this problem might need to do something similar. -- Ticket URL: <https://code.djangoproject.com/ticket/17816#comment:14> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/080.fadc2d7230efebfcbaf4dadb3db39968%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.